Last active
August 29, 2015 14:01
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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