UNPKG

isaacscript-common

Version:

Helper functions and features for IsaacScript mods.

47 lines 1.35 kB
export declare function sortNormal(a: unknown, b: unknown): -1 | 0 | 1; /** * Helper function to sort an array of objects by one of the object keys. * * For example: * * ```ts * const myArray = [ * { * name: "alice", * age: 30, * }, * { * name: "bob", * age: 20, * }, * ]; * myArray.sort(sortObjectArrayByKey("age")); * ``` */ export declare function sortObjectArrayByKey(key: string): (a: unknown, b: unknown) => -1 | 0 | 1; /** * Helper function to sort a two-dimensional array by the first element. * * For example: * * ```ts * 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 */ export declare function sortTwoDimensionalArray<T>(a: readonly T[], b: readonly T[]): -1 | 0 | 1; /** * 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. */ export declare function stableSort<T>(array: T[], sortFunc?: (a: T, b: T) => -1 | 0 | 1): T[]; //# sourceMappingURL=sort.d.ts.map