2 ms·
The article itself is quite useful, but a warning on the sort tutorial he links to (http://www.javascriptkit.com/javatutors/arraysort.shtml http://www.javascrip
by _delirium 17y ago
The article itself is quite useful, but a warning on the sort tutorial he links to (http://www.javascriptkit.com/javatutors/arraysort.shtml http://www.javascriptkit.com/javatutors/arraysort.shtml). Contrary to what it says, you cannot reliably shuffle a list by doing:
myarray.sort(function() {return 0.5 - Math.random()})
This just makes every comparison return a random value, which may or may not produce particularly random results, depending on the sort algorithm. It's exactly the bug that bit Microsoft in their not-very-random browser shuffle screen.