So I was reading about shuffling an array. And then I came across this script:
shuffle = function(o){ //v1.0
for(var j, x, i = o.length; i; j = parseInt(
All the work is actually being done within the parens of the for
statement. There is not explicit body for the loop so the ;
at the end just says that the body is an empty statement.
The ,
(comma) operator evaluates expressions from left to right, and returns the value of the right-most.
The loop is basically equivalent to:
for(var j, x, i = o.length; i > 0;)
{
j = parseInt(Math.random() * i--);
x = o[i];
o[i] = o[j];
o[j] = x
}