Skip to content

Instantly share code, notes, and snippets.

@jackhooper
Created January 19, 2014 06:36
Show Gist options
  • Save jackhooper/8501281 to your computer and use it in GitHub Desktop.
Save jackhooper/8501281 to your computer and use it in GitHub Desktop.
Extensible FizzBuzz implementation (based around string concatenation), written in Ruby.
# 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