Skip to content

Sort

sortNormal(a, b): -1 | 0 | 1

Defined in: packages/isaacscript-common/src/functions/sort.ts:3

unknown

unknown

-1 | 0 | 1


sortObjectArrayByKey(key): (a, b) => -1 | 0 | 1

Defined in: packages/isaacscript-common/src/functions/sort.ts:50

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"));

string

(a, b) => -1 | 0 | 1


sortTwoDimensionalArray<T>(a, b): -1 | 0 | 1

Defined in: packages/isaacscript-common/src/functions/sort.ts:91

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

T

readonly T[]

readonly T[]

-1 | 0 | 1


stableSort<T>(array, sortFunc?): T[]

Defined in: packages/isaacscript-common/src/functions/sort.ts:152

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.

T

T[]

(a, b) => -1 | 0 | 1

T[]