Skip to content

Instantly share code, notes, and snippets.

@dstavis
Created December 15, 2013 23:36
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 dstavis/7979892 to your computer and use it in GitHub Desktop.
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…
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