Skip to content

Instantly share code, notes, and snippets.

@Stephenitis
Created February 23, 2013 00:36
Show Gist options
  • Save Stephenitis/5017675 to your computer and use it in GitHub Desktop.
Save Stephenitis/5017675 to your computer and use it in GitHub Desktop.
super fizzbuzz exercise
def super_fizzbuzz(array)
new_array = [] #create a new array to store the results
#reminder to make sure that two word variables are seperated by a underscore_k?
array.each do |x|
if x % 15 == 0
new_array << "FizzBuzz" #remember stephen the << is the same as saying array.push("FizzBuzz")
elsif x % 5 == 0
new_array << "Buzz"
elsif x % 3 == 0
new_array << "Fizz"
else
new_array << x #if it does not meet any of the if/elsif statements then the newarray is filled with original value
end
end
return new_array #this will return the array without displaying it
print new_array #this will show me my results
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment