3 ms·
This seems a far more obvious way to code the extensible case: def fizzbuzz(max) (1..max).each do |n| labels = [] labels << "fizz" i
by ollysb 14y ago
This seems a far more obvious way to code the extensible case:
def fizzbuzz(max)
(1..max).each do |n|
labels = []
labels << "fizz" if n % 3 == 0
labels << "buzz" if n % 5 == 0
labels << "bazz" if n % 7 == 0
puts labels.empty? ? n : labels.join
end
end
fizzbuzz(105)