1 2 3 4 |
function shuffle(array) { for(var j, x, i = array.length; i; j = Math.floor(Math.random() * i), x = array[--i], array[i] = array[j], array[j]= x); return array; }; |
Found this incredible loop on Stack Overflow while looking for an array method to shuffle my array. I was trying to do all of the above with basic iteration, but this is an incredible find.
This is my little exercise: what do these elements of the loop do?