mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-05 23:38:38 +09:00
Issue #2551 - comment toSorted implementation
This commit is contained in:
parent
d4658401f7
commit
75db223e08
1 changed files with 5 additions and 0 deletions
|
|
@ -261,15 +261,18 @@ function ArrayToSorted(comparefn) {
|
|||
}
|
||||
}
|
||||
|
||||
// Step 1: Let O be ? ToObject(this). Let len be ? ToLength(O.length).
|
||||
var O = ToObject(this);
|
||||
var len = ToLength(O.length);
|
||||
|
||||
// Step 2: Snapshot values in ascending index order into a List.
|
||||
var items = new List();
|
||||
var itemsLen = len;
|
||||
for (var k = 0; k < len; k++) {
|
||||
items[k] = O[k];
|
||||
}
|
||||
|
||||
// Step 3: Create SortCompare per spec.
|
||||
var wrappedCompareFn = comparefn;
|
||||
var sortCompare;
|
||||
if (wrappedCompareFn === undefined) {
|
||||
|
|
@ -299,9 +302,11 @@ function ArrayToSorted(comparefn) {
|
|||
};
|
||||
}
|
||||
|
||||
// Step 4: Sort the snapshot List using SortCompare.
|
||||
if (itemsLen > 1)
|
||||
MergeSort(items, itemsLen, sortCompare);
|
||||
|
||||
// Step 5: Create result array and write sorted values.
|
||||
var A = ArraySpeciesCreate(O, len);
|
||||
for (var j = 0; j < itemsLen; j++)
|
||||
_DefineDataProperty(A, j, items[j]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue