Here is my simple answer to a typical test given during interviews
class FizzBuzz
FIZZ = 'Fizz'
BUZZ = 'Buzz'
def FizzBuzz.fizz_it(iterations = 100)
(1..iterations).map do |i|
fizz = FIZZ if i % 3 == 0
buzz = BUZZ if i % 5 == 0
(fizz || buzz) ? "#{fizz}#{buzz}" : i
end.join(', ')
end
end
You must log in to post a comment.