Sort
Functions
sortNormal
▸ sortNormal(a
, b
): -1
| 0
| 1
Parameters
Name | Type |
---|---|
a | unknown |
b | unknown |
Returns
-1
| 0
| 1
Defined in
packages/isaacscript-common/src/functions/sort.ts:3
sortObjectArrayByKey
▸ sortObjectArrayByKey(key
): (a
: unknown
, b
: unknown
) => -1
| 0
| 1
Helper function to sort an array of objects by one of the object keys.
For example:
const myArray = [
{
name: "alice",
age: 30,
},
{
name: "bob",
age: 20,
},
];
myArray.sort(sortObjectArrayByKey("age"));
Parameters
Name | Type |
---|---|
key | string |
Returns
fn
▸ (a
, b
): -1
| 0
| 1
Parameters
Name | Type |
---|---|
a | unknown |
b | unknown |
Returns
-1
| 0
| 1
Defined in
packages/isaacscript-common/src/functions/sort.ts:50
sortTwoDimensionalArray
▸ sortTwoDimensionalArray<T
>(a
, b
): -1
| 0
| 1
Helper function to sort a two-dimensional array by the first element.
For example:
const myArray = [[1, 2], [2, 3], [3, 4]];
myArray.sort(sortTwoDimensionalArray);
This function also properly handles when the array elements are strings or numbers (instead of another array).
From: https://stackoverflow.com/questions/16096872/how-to-sort-2-dimensional-array-by-column-value
Type parameters
Name |
---|
T |
Parameters
Name | Type |
---|---|
a | readonly T [] |
b | readonly T [] |
Returns
-1
| 0
| 1
Defined in
packages/isaacscript-common/src/functions/sort.ts:91
stableSort
▸ stableSort<T
>(array
, sortFunc?
): T
[]
Helper function to sort an array in a stable way.
This is useful because by default, the transpiled Array.sort
method from TSTL is not stable.
Under the hood, this uses the merge sort algorithm.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Default value |
---|---|---|
array | T [] | undefined |
sortFunc | (a : T , b : T ) => -1 | 0 | 1 | sortNormal |
Returns
T
[]