News for hackers. Stuff that matters.
Re:Hiring Front-End Engineers by tantalor on Thursday January 20, 2011 @10:34PM (#2126350)
Solution to the puzzle; took about 3 to code minutes after I found the thumbnails for the slideshow.

https://gist.github.com/789200

Re:Hiring Front-End Engineers by asmithmd1 on Thursday January 20, 2011 @10:51PM (#2126378)
I like this slick way cycle thru a range of numbers:

c = c < 4 ? c + 1 : 0;

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.

Re:Hiring Front-End Engineers by tydok on Friday January 21, 2011 @06:11AM (#2127072)
just a correction. The equivalent to the above is: c = (c + 1) % 5
Re:Hiring Front-End Engineers by rudasn on Friday January 21, 2011 @04:54AM (#2126969)
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.
Re:Hiring Front-End Engineers by tantalor on Friday January 21, 2011 @12:08AM (#2126525)
Agreed, that is definitely more clear.

Alternatively, increment with c++ and replace [c] with [c%4].

Re:Hiring Front-End Engineers by formika on Thursday January 20, 2011 @11:31PM (#2126460)

  c = c < 4 ? c + 1 : 0;
What is this line of code saying exactly.. ?
Re:Hiring Front-End Engineers by ericras on Thursday January 20, 2011 @11:44PM (#2126487)
http://en.wikipedia.org/wiki/Ternary_operation

  if (c < 4) {
   c = c + 1;
  } else {
   c = 0;
  }
Re:Hiring Front-End Engineers by rudasn on Friday January 21, 2011 @04:57AM (#2126974)
You could learn a couple of things just by looking the code of others. If you use jQuery you can see the source and find this kind of code in many places. Also:

    var x = a || b || (function(){ /* stuff here */ })()
or

    var a = b = b || {}