![](/img/trans.png)
[英]JS Array.prototype.sort() failing in Firefox, works in Chrome
[英]I want to know how Array.prototype.sort works basically polyfill of sort function
我知道排序在JS中的工作原理,但想知道Array.prototype.sort是如何實現的,基本上是對sort函數,算法或其他任何細節的polyfill
我在這里找不到https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
如果您有興趣,請參閱Array.protoype.sort的規范: http : //www.ecma-international.org/ecma-262/5.1/#sec-15.4.4.11
它沒有規定要使用哪種排序算法,所以這取決於瀏覽器的實現。
The time and space complexity of the sort cannot be guaranteed as it is implementation dependent.
function reverse(a[0..n - 1])
allocate b[0..n - 1]
for i from 0 to n - 1
b[n − 1 − i] := a[i]
return b
function reverse_in_place(a[0..n-1])
for i from 0 to floor((n-2)/2)
tmp := a[i]
a[i] := a[n − 1 − i]
a[n − 1 − i] := tmp
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.