0

On ES2019 Array.prototype.sort() must be stable sort.

But IE11's sort() function doesn't support stable sort.

So this program doesn't work correctly on IE11.

someArray
  .sort((a, b) => a.att1 - b.att1)
  .sort((a, b) => a.att2 - b.att2)

I know Polyfill support undefined function.

But IE11's Array.prototype.sort() is defined and doesn't satisfy ES2019.

How to avoid this bug?

I'm using vue-cli (or webpack). Please tell me the solve.

And I can't stand to learn all IE11's bug.

Is there a way to solve this easily like webpack's or babel's config?

tasasei
  • 1
  • 1
  • As a workaround, you could insert a `position` property on each element of the array that's their initial order. Then if `a.att1 == b.att1`, then you use the position as the tie breaker. – selbie Mar 10 '21 at 00:16
  • I test in IE 11 but it seems that the `sort()` is stable. Have you polyfill the arrow function in your code? Please try [this code](https://jsfiddle.net/30fsvbuc/) in Chrome and IE 11, the results are the same and the sort is stable. I also find [a thread](https://stackoverflow.com/questions/3026281/what-is-the-stability-of-the-array-sort-method-in-different-browsers) and you can refer to the accepted answer, it also says sort is stable in IE6+. – Yu Zhou Mar 10 '21 at 06:32

0 Answers0