Module: FizzBuzzer::V12a
- Defined in:
- lib/fizzbuzzer.rb
Instance Method Summary collapse
Instance Method Details
#fizzbuzz ⇒ Object
350 351 352 353 |
# File 'lib/fizzbuzzer.rb', line 350 def fizzbuzz fizzbuzz_engine( 1..100, [["Fizz", -> n { n % 3 == 0 }], ["Buzz", -> n { n % 5 == 0 }]]) end |
#fizzbuzz_engine(range, factors) ⇒ Object
340 341 342 343 344 345 346 347 348 |
# File 'lib/fizzbuzzer.rb', line 340 def fizzbuzz_engine(range, factors) range.map do |n| result = "" factors.each do |(name, predicate)| result << name if predicate.call(n) end result == "" ? n : result end end |