-2

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?

1 Answer 1

1

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().

Sign up to request clarification or add additional context in comments.

2 Comments

which algorithms are used by v8 and spider monkey?
@JobinMathew always Google before you ask. This post easily came up.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.