Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
_delirium
on April 20, 2010
|
parent
|
context
|
favorite
| on:
JavaScript Things I Wish I Knew Much Earlier In My...
The article itself is quite useful, but a warning on the
sort
tutorial he links to (
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.
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search: