-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?

Jobin Mathew
  • 477
  • 4
  • 7

1 Answers1

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

Patrick Roberts
  • 40,065
  • 5
  • 74
  • 116