Super Modulo

Adames H.
1 min readSep 25, 2017

--

Working with 12 hour time? Why not modulo?

The modulo (%) operator is definitely my favorite operator. New coders should become comfortable with the action. For those unaware, the modulo operator is is similar to the division operator, only it returns the remainder.
5 % 3 = 1
5 % 11 = 5
101 % 2 = 1

OK, Adames, so what’s the big deal?

Want to equally divvy up actions to different items in an array?
for i in infinity { array[i % array.length] }

Want to navigate columns in a grid?
column = cell number % number_of_columns

Want to check if an International Bank Account Number (IBAN) is legit?
IBAN % 97 == 1

OK, that last one is a little more complicated than I’ve described, but cool nonetheless. So get out there and use that modulo!

--

--