Created
December 15, 2013 23:36
-
-
Save dstavis/7979892 to your computer and use it in GitHub Desktop.
Exercise: Implement FizzBuzz (Super Edition)
FizzBuzz is a classic programming exercise. The usual example asks the developer to write a program which prints out each number from 1 to 100. But for multiples of 3 print 'Fizz' instead of the number and for multiples of 5 print 'Buzz'. For numbers which are multiples of both 3 and 5 print '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 super_fizzbuzz(array) | |
#It should return a "fizzbuzzed" Array, i.e., the array is identical to the input with the following substitutions: | |
array.each do |number| | |
#Multiples of 3 should be replaced with the string "Fizz" | |
#Multiples of 5 should be replaced with the string "Buzz" | |
#Multiples of 15 should be replaced with the string "FizzBuzz" | |
if number % 3 == 0 | |
number = "Fizz" | |
elsif | |
number % 5 == 0 | |
number = "Buzz" | |
elsif | |
number % 15 == 0 | |
number = "FizzBuzz" | |
end#if | |
end#each | |
return array | |
end#def |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment