Here are the fully tested solutions to the coding test, it took another 20 minutes to complete the testing and to optimize them in RStudio.
fizbuz<-function(){ #vectorized is faster
r<-seq(100)
r3<-!r%%3
r5<-!r%%5
r[r3]<-"fiz"
r[r5]<-"buz"
r[r3&r5]<-"fizbuz"
return(r)
}# end function fizbuz
fizbuz()
## [1] "1" "2" "fiz" "4" "buz" "fiz" "7"
## [8] "8" "fiz" "buz" "11" "fiz" "13" "14"
## [15] "fizbuz" "16" "17" "fiz" "19" "buz" "fiz"
## [22] "22" "23" "fiz" "buz" "26" "fiz" "28"
## [29] "29" "fizbuz" "31" "32" "fiz" "34" "buz"
## [36] "fiz" "37" "38" "fiz" "buz" "41" "fiz"
## [43] "43" "44" "fizbuz" "46" "47" "fiz" "49"
## [50] "buz" "fiz" "52" "53" "fiz" "buz" "56"
## [57] "fiz" "58" "59" "fizbuz" "61" "62" "fiz"
## [64] "64" "buz" "fiz" "67" "68" "fiz" "buz"
## [71] "71" "fiz" "73" "74" "fizbuz" "76" "77"
## [78] "fiz" "79" "buz" "fiz" "82" "83" "fiz"
## [85] "buz" "86" "fiz" "88" "89" "fizbuz" "91"
## [92] "92" "fiz" "94" "buz" "fiz" "97" "98"
## [99] "fiz" "buz"
swapUL<-function(string) {
b<-unlist(strsplit(string,""))
low<-b %in% letters
high<-b %in% LETTERS
b[low]<-toupper(b[low])
b[high]<-tolower(b[high])
return(paste(b, sep="", collapse=""))
}
swapUL("abcDEF123")
## [1] "ABCdef123"
# show R package and function used.
library(gtools)
permutations(3, 3, letters[1:3])
## [,1] [,2] [,3]
## [1,] "a" "b" "c"
## [2,] "a" "c" "b"
## [3,] "b" "a" "c"
## [4,] "b" "c" "a"
## [5,] "c" "a" "b"
## [6,] "c" "b" "a"
#string<-"abc"
perms<-function(string){
#string<-"abc"
b<-unlist(strsplit(string,""))
len<-length(b)
p<-permutations(len, len, b)
pa<-apply(p,1,paste,sep="",collapse="")
return(pa)
}
perms("abcd")
## [1] "abcd" "abdc" "acbd" "acdb" "adbc" "adcb" "bacd" "badc" "bcad" "bcda"
## [11] "bdac" "bdca" "cabd" "cadb" "cbad" "cbda" "cdab" "cdba" "dabc" "dacb"
## [21] "dbac" "dbca" "dcab" "dcba"