Created
July 24, 2013 15:26
-
-
Save siciliana/6071603 to your computer and use it in GitHub Desktop.
Super Fizz Buzz http://socrates.devbootcamp.com/exercises/22
This file contains hidden or 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) | |
| new_arr = [] | |
| (array).each do |i| | |
| if (i % 3).zero? && (i % 15) != 0 | |
| puts new_arr <<'Fizz' | |
| elsif (i % 5).zero? && (i % 15) != 0 | |
| puts new_arr << 'Buzz' | |
| elsif (i % 15).zero? | |
| puts new_arr <<'FizzBuzz' | |
| else | |
| puts i | |
| end | |
| end | |
| end |
Your else is not actually adding any values to the array. It is just puts-ing them.
Author
so new_arr not altogether necessary?
Author
SCORE!!
def super_fizzbuzz(array)
(array).map! { |i|
if (i % 3).zero? && (i % 15) != 0
'Fizz'
elsif (i % 5).zero? && (i % 15) != 0
'Buzz'
elsif (i % 15).zero?
'FizzBuzz'
else
i
end
}
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is that
new_arrdoing for you?