I heard this was a common interview question, any ideas what is off here, thank you.
for(i in 1:100){
if(i%15==0){
print('fizzbuzz')
} else
if (i%3==0){
print("fizz")
} else
if (i%5==0) {
print("buzz")
} else
(print(i))
}
}
Would you mind to rate my approach? What would you consider as "elegant" for FizzBuzz in R?
x <- c(1:100)
y <-ifelse(x/3 == round(x/3, digits=0) & x/5 == round(x/5, digits=0), "FizzBuzz",
ifelse(x/3 == round(x/3, digits=0), "Fizz",
ifelse(x/5 == round(x/5, digits=0), "Buzz",
x)))
print(y)