Skip to content

Instantly share code, notes, and snippets.

@wbars
Created April 27, 2015 06:44
Show Gist options
  • Save wbars/b367d17a40425d9e909f to your computer and use it in GitHub Desktop.
Save wbars/b367d17a40425d9e909f to your computer and use it in GitHub Desktop.
def fizzbuzz(range, triggers)
range.map do |i|
parts = triggers.select{ |(_, predicate)| predicate.call(i) }
parts.size > 0 ? parts.map(&:first).join : i
end
end
puts fizzbuzz(1..100, [
['Fizz', ->(i){ i % 3 == 0 }],
['Buzz', ->(i){ i % 5 == 0 }],
['Zazz', ->(i){ i < 10 }],
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment