本文介绍了Array.sort在不同浏览器中排序稳定性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 Array.sort在不同浏览器中的稳定性是什么?我知道ECMA脚本规范没有指定使用哪个算法,也没有指定排序是否应该稳定。What is the stability of Array.sort in different browsers. I know that the ECMA Script specification does not specify which algorithm to use, nor does it specify whether the sort should be stable.我已经找到这个信息为Firefox https://developer.mozilla.org/en/ Core_JavaScript_1.5_Reference / Global_Objects / Array / sort 它指定firefox使用稳定的排序。I've found this information for Firefox athttps://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/sort which specifies that firefox uses a stable sort.有人知道IE 6/7 / 8,Chrome,Safari?Does anyone know about IE 6/7/8, Chrome, Safari?推荐答案 简单测试用例(忽略标题,如果引擎的排序稳定,第二组数字应该是顺序的)。Simple test case (ignore the heading, second set of numbers should be sequential if the engine's sort is stable). IE的排序已经稳定,只要我曾经使用它(所以IE6)。再次检查IE8,它似乎仍然是这种情况。 IE's sort has been stable as long as I've ever used it (so IE6). Checking again in IE8 and it appears to still be the case. 虽然你链接的Mozilla页面说Firefox的排序是稳定的,但我绝对认为这并不总是在Firefox 2.0之前(包括)。And although that Mozilla page you link to says Firefox's sort is stable, I definitely say this was not always the case prior to (and including) Firefox 2.0.有些粗略的结果: IE6 +: stable li> Firefox< 3:不稳定 Firefox> = 3:稳定 Chrome Opera Opera> = 10:稳定 Safari 4:稳定 IE6+: stableFirefox < 3: unstableFirefox >= 3: stableChrome <= 5 (i.e., all versions to date): unstableOpera < 10: unstableOpera >= 10: stableSafari 4: stable Windows上的所有测试。All tests on Windows.另请参阅: 在JavaScript中快速稳定排序算法的实现 Fast stable sorting algorithm implementation in javascript 这篇关于Array.sort在不同浏览器中排序稳定性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-19 04:51