-
-
Save harrysboileau/6015621 to your computer and use it in GitHub Desktop.
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 |
Check out the other iterative methods there are for Arrays besides each
that you can use
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.
On line 14, why do you put "puts new_array.inspect". Try "return new_array" and see what it does
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....
you need to assign an array to a variable. Then, for each conditional statement, push the return into that array!