DEV Community

Discussion on: 10 Popular JavaScript methods implemented from scratch

Collapse
 
rajesh6161 profile image
Rajesh Ranjan

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.

Collapse
 
northwillov profile image
Artem Verbitski

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