Re:Hiring Front-End Engineers
by nostrademons on Thursday January 20, 2011 @11:22PM
(#2126450)
I tend to prefer c = (c + 1) % 4.
It's shorter (which matters for client-side code), and makes it more explicit what you're attempting to accomplish.
just a correction. The equivalent to the above is: c = (c + 1) % 5
I really regret not paying attention to maths at school. What exactly is the % doing there? What is the purpose of % normally?
Re:Hiring Front-End Engineers
by nostrademons on Friday January 21, 2011 @05:06AM
(#2126988)
% is the modulus operator. It's the remainder when you divide...so 0 % 4 == 0, 1 % 4 == 1, 2 % 4 == 2, 3 % 4 == 3, then 4 % 4 == 0 again. It's useful in that the result cycles through 0 <= x % n < n.
c = c < 4 ? c + 1 : 0;