Skip to content

Instantly share code, notes, and snippets.

@dhruvasagar
Created February 5, 2016 15:28
Show Gist options
  • Select an option

  • Save dhruvasagar/31bb633e48a57d360617 to your computer and use it in GitHub Desktop.

Select an option

Save dhruvasagar/31bb633e48a57d360617 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
def fizz(num)
num % 3 == 0 ? "Fizz" : nil
end
def buzz(num)
num % 5 == 0 ? "Buzz" : nil
end
def fizzbuzz(iter)
iter.map do |i|
[fizz(i), buzz(i), fizz(i) || buzz(i) || i].compact.uniq.join
end
end
puts fizzbuzz(1..100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment