News for hackers. Stuff that matters.
Re:JavaScript Interview Question by lhorie on Thursday January 20, 2011 @01:43PM (#2124729)
I don't generally care too much to talk about style when the problem at hand is that someone has been banging their head against the desk for the past two hours and they just want it to work (and, in my experience, this usually is the case, for some reason)

But yeah, if we're gonna be super nitpicky, yeah sure, improve the for loop also, while we're at it.

  for (var i = -1; els[++i];) {//given the code in the loop body, this is shorter and faster
Re:JavaScript Interview Question by heed on Thursday January 20, 2011 @02:50PM (#2125010)
Wouldn't var i have to be set to -1:

  for (var i = -1; els[++i];)  ?
Otherwise, the alert won't trigger on the first li element.
Re:JavaScript Interview Question by lhorie on Thursday January 20, 2011 @02:56PM (#2125047)
Hah, good catch. Was thinking of i++ for some reason. Fixed.