“FizzBuzz” code test

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

Chapley Watson
Husband, Father, Software Developer, Attempted Writer, and many other things depending on the day.
%d bloggers like this: