As ECMAScript doesn’t specify any sorting algorithm to be implemented by Array.prototype.sort(), it totally depends on browser which sorting algorithm to be implement.
Safari, Webkit, etc. uses 'Selection Sort' whereas Mozilla uses 'Merge Sort'.
The sorting algorithm behind .fakeSort() mentioned in this article is 'Bubble Sort', and is intended for educational purposes and isn’t an efficient method for sorting in real world.
Bubble Sort also is one of the most widely discussed algorithms, simply because of its lack of efficiency for sorting arrays. If an array is already sorted, Bubble Sort will only pass through the array once, however the worst case scenario is a run time of O(N²), which is extremely inefficient.
Some comments have been hidden by the post's author - find out more
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Good try but most of the Algorithms are wayyyyyy too slow to use, for example, your sort algorithm is taking O(N^2) time too slow.
As ECMAScript doesn’t specify any sorting algorithm to be implemented by
Array.prototype.sort()
, it totally depends on browser which sorting algorithm to be implement.Safari, Webkit, etc. uses 'Selection Sort' whereas Mozilla uses 'Merge Sort'.
The sorting algorithm behind
.fakeSort()
mentioned in this article is 'Bubble Sort', and is intended for educational purposes and isn’t an efficient method for sorting in real world.Bubble Sort also is one of the most widely discussed algorithms, simply because of its lack of efficiency for sorting arrays. If an array is already sorted, Bubble Sort will only pass through the array once, however the worst case scenario is a run time of O(N²), which is extremely inefficient.