Last active
August 29, 2015 14:27
-
-
Save kangkyu/14eb89318369bf375efe to your computer and use it in GitHub Desktop.
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
def fizz(number) | |
number % 3 == 0 ? "fizz" : "" | |
end | |
def buzz(number) | |
number % 5 == 0 ? "buzz" : "" | |
end | |
def fizz_buzz(number) | |
(number.to_s + " " + fizz(number) + buzz(number)) | |
.chomp(" ") | |
end | |
def run_fizz_buzz(limit) | |
(1..limit).each do |number| | |
puts fizz_buzz(number) | |
end | |
end | |
run_fizz_buzz(100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you @charliemcelfresh for your comment. I also made an additional change, I pulled out
fizz
andbuzz
as separate methods.