Skip to content

Instantly share code, notes, and snippets.

@greghaskins
Last active August 29, 2015 14:01
Show Gist options
  • Save greghaskins/021bc78fcf77f5be7d11 to your computer and use it in GitHub Desktop.
Save greghaskins/021bc78fcf77f5be7d11 to your computer and use it in GitHub Desktop.
FizzBuzz kata written as an R function. Logic implemented with array subsetting instead of loops.
fizzbuzz <- function(){
input <- seq(1, 100)
result <- input
result[input %% 3 == 0] <- "Fizz"
result[input %% 5 == 0] <- "Buzz"
result[input %% 15 == 0] <- "FizzBuzz"
result
}
fizzbuzz()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment