Advanced Javascript tips and tricks
<p><pre><code>  list = list.sort(function() Math.random() - 0.5);
</code></pre>
Please don't shuffle an array like this. Array.prototype.sort requires the comparison function to be referentially transparent (i.e. to always return the same result when given the same two elements to compare), otherwise the sort order is undefined. For example, imagine how far from "shuffled" the resulting array will be if a bubble sort is used with a randomised comparison function.<p>Use a Fisher-Yates shuffle instead.