Created
September 24, 2017 08:01
-
-
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
This file contains hidden or 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
## 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