Skip to content

Instantly share code, notes, and snippets.

@harrysboileau
Last active December 19, 2015 20:49
Show Gist options
  • Save harrysboileau/6015621 to your computer and use it in GitHub Desktop.
Save harrysboileau/6015621 to your computer and use it in GitHub Desktop.
I know this isn't correct, but it's currently as far as I've been able to get with SuperFizzBuzz. I can return 'FizzBuzz' when I have a multiple of 15, Fizz when 3, Buzz when 5, but I am stuck on how to put those values back into the array, and ultimately return that altered array. Any thoughts/direction/hint would be very appreciated, thanks!
def super_fizzbuzz(array)
new_array = []
array.each do |x|
if x % 15 == 0
new_array.push('FizzBuzz')
elsif x % 3 == 0
new_array.push('Fizz')
elsif x % 5 == 0
new_array.push('Buzz')
else
new_array.push(x)
end
end
return new_array
end
@christianrjo
Copy link

you need to assign an array to a variable. Then, for each conditional statement, push the return into that array!

@kmazanec
Copy link

Check out the other iterative methods there are for Arrays besides each that you can use

http://www.ruby-doc.org/core-2.0/Array.html

@harrysboileau
Copy link
Author

Thanks so much for the tips guys!

I first tried to take your advice, Christian, and came up with the solution above. It's giving me the correct results when I run it locally, but I'm getting all sorts of errors when I run it in Socrates. Does my solution look like what you were suggesting?

Keith, thanks for the tip, I'm definitely going to try and use a better method to clean this up, hopefully with some refactoring to make it a little less repetitive too.

@christianrjo
Copy link

On line 14, why do you put "puts new_array.inspect". Try "return new_array" and see what it does

@harrysboileau
Copy link
Author

Thanks so much Christian and Keith!That was my lingering issue. Now I've got it working....but could clearly be cleaner with a bit of refactoring....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment