Skip to content

Instantly share code, notes, and snippets.

@prodoxx
Created September 24, 2017 08:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prodoxx/30a9de0fa491f1b4a0333fb8e63a8e64 to your computer and use it in GitHub Desktop.
Save prodoxx/30a9de0fa491f1b4a0333fb8e63a8e64 to your computer and use it in GitHub Desktop.
Fizz buzz is a simple children’s game where everyone sits in a circle, and each person takes a turn saying numbers in increasing order. More here: http://en.wikipedia.org/wiki/Fizz_buzz
## write your fizzbuzz method in this file
# see http://en.wikipedia.org/wiki/Fizz_buzz for details on FizzBuzz game
def get_fb(number)
return 'FizzBuzz' if (number % 5).zero? && (number % 3).zero?
return 'Fizz' if (number % 3).zero?
return 'Buzz' if (number % 5).zero?
number
end
def fizzbuzz(size, &optional)
sayings = []
size.times do |index|
counter = index + 1
sayings.push(get_fb(counter))
yield get_fb(counter) if optional
end
sayings
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment