I am trying to return an array containing the numbers from 1 to N, where N will never be less than 1, with the following conditions:
- If the value is a multiple of
3: use the value'Fizz'instead. - If the value is a multiple of
5: use the value'Buzz'instead. - If the value is a multiple of
3and5: use the value'FizzBuzz'instead.
This is what I have right now. Am I going in the right direction?
def fizzbuzz(n)
x = [1..n]
x.map { |i|
if (i % 3 == 0 && i % 5 == 0)
'FizzBuzz'
elsif (i % 3 == 0 && i % 5 != 0)
'Fizz'
elsif (i % 5 == 0 && i % 3 != 0)
'Buzz'
end
puts x
end