Is algorithms for JavaScript functions on different JavaScript engine varies?
I run Array.sort()
in Chrome and Firefox browser, and two of them perform differently for the same code.
Are they used different algorithms for the same code?
Is algorithms for JavaScript functions on different JavaScript engine varies?
I run Array.sort()
in Chrome and Firefox browser, and two of them perform differently for the same code.
Are they used different algorithms for the same code?
Copyright © 2021 Jogjafile Inc.
All that's guaranteed by the specification is a non-stable in-place sorting method.
So yes, different implementations are allowed to use different algorithms, and because the specification does not guarantee a stable algorithm, different non-stable algorithms will result in different orders if your array values evaluate as equal, which is any falsy return value from the compare function you pass to
Array.prototype.sort()
.