Ruby: divisible by 4
This is always a good conversation starter:
if (i & 3).zero?
Try this:
if i % 4 == 0
This is called the "modulo operator".
There's also modulo
, which allows you to do
420.modulo(4).zero?
There's nothing stopping you doing that with %
, but it looks weird:
420.%(4).zero?