Created
January 19, 2014 06:36
-
-
Save jackhooper/8501281 to your computer and use it in GitHub Desktop.
Extensible FizzBuzz implementation (based around string concatenation), written in Ruby.
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
# Jack Hooper 2014 | |
def fizzbuzz(n) | |
output = "" | |
output.concat("Fizz") if n.modulo(3).zero? | |
output.concat("Buzz") if n.modulo(5).zero? | |
return n if output.empty? | |
output | |
end | |
1.upto(100) { |i| puts fizzbuzz(i) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment