What is the stability of the Array.sort() method in different browsers?

后端 未结 4 528
广开言路
广开言路 2020-11-22 12:15

I know that the ECMA Script specification does not specify which algorithm to use for sorting arrays, nor does it specify whether the sort should be stable.

I\'ve fo

4条回答
  •  隐瞒了意图╮
    2020-11-22 13:07

    If you are looking for a list of browsers where you should utilize a non native sorting algorithm, my suggestion is don't.

    Instead do a sort sanity check when the script loads and make your decision from that.

    As the spec doesn't require a particular behavior in that regard, it is not immune to later change, even within the same browser line.

    You could submit a patch to http://www.browserscope.org/ to include such tests in their suite. But again, feature detection is superior to browser detection.

提交回复
热议问题