3 ms·
You can write Ruby in this fashion as well. def fizzbuzz x case [x % 3 == 0, x % 5 == 0] when [true, false] then puts "fizz" when [false, tru
by Jweb_Guru 12y ago
You can write Ruby in this fashion as well.
def fizzbuzz x
case [x % 3 == 0, x % 5 == 0]
when [true, false] then puts "fizz"
when [false, true] then puts "buzz"
when [true, true] then puts "fizzbuzz"
else puts x
end
end
The one and only time I was asked FizzBuzz in an interview, I wrote it this way, so it's not all that contrived (in my opinion, anyway!)