4 ms·
How to properly shuffle arrays in JavaScript
- malka 13y ago"The Array.sort() method uses a Bubble Sort algorithm." Seriously ? why the hell would anyone use this algorithm ?
- dalke 13y agoThe author appears to be completely wrong. While the spec doesn't say anything about the expected performance, there's no way a real Javascript implementation uses an O(n * n) algorithm. Indeed, http://blog.rodneyrehm.de/archives/14-Sorting-Were-Doing-It-Wrong.html http://blog.rodneyrehm.de/archives/14-Sorting-Were-Doing-It-... a couple of years ago wrote "While InsertionSort and MergeSort (Apple and Mozilla) are stable, QuickSort (Google Chrome) is not (Issue 90). Chrome will sort arrays using InsertionSort if the array has 10 or less elements" and http://stackoverflow.com/questions/234683/javascript-array-sort-implementation http://stackoverflow.com/questions/234683/javascript-array-s... agrees. http://webreflection.blogspot.se/2009/04/internet-explorer-and-its-inefficient.html http://webreflection.blogspot.se/2009/04/internet-explorer-a... extends the comparison to IE and Opera, showing that they are also n * log n implementations.