Created
February 24, 2015 16:53
-
-
Save nestorsalceda/3f6306133fd195a9ed64 to your computer and use it in GitHub Desktop.
Basic Fizzbuzz
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
def is_fizz(number) | |
number % 3 == 0 and number.to_s[-1] == "3" | |
end | |
def is_buzz(number) | |
number % 5 == 0 and number.to_s[-1] == "5" | |
end | |
def fizzbuzz(number) | |
return 'FizzBuzz' if is_fizz(number) and is_buzz(number) | |
return 'Fizz' if is_fizz(number) | |
return 'Buzz' if is_buzz(number) | |
number | |
end | |
1.upto(20) do |number| | |
puts fizzbuzz(number) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment