Sort
Functions
Section titled “Functions”sortNormal()
Section titled “sortNormal()”sortNormal(
a,b):-1|0|1
Defined in: packages/isaacscript-common/src/functions/sort.ts:3
Parameters
Section titled “Parameters”unknown
unknown
Returns
Section titled “Returns”-1 | 0 | 1
sortObjectArrayByKey()
Section titled “sortObjectArrayByKey()”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"));Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”(a, b) => -1 | 0 | 1
sortTwoDimensionalArray()
Section titled “sortTwoDimensionalArray()”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
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”readonly T[]
readonly T[]
Returns
Section titled “Returns”-1 | 0 | 1
stableSort()
Section titled “stableSort()”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.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”T[]
sortFunc?
Section titled “sortFunc?”(a, b) => -1 | 0 | 1
Returns
Section titled “Returns”T[]
