sortWithIndex
Input an array arr
, sort arr
, and return an array representing the mapping from the indices of the original array to the indices of the sorted array.
The sortIndex will be called internally.
Note that the array arr
itself will be sorted!
A custom comparator comparator
can be provided; if not provided, the comparison logic will be the same as the native sort
.
Added in v0.0.2
Usage
ts
// Usage
API
Type Parameter
Arg | Type | Description |
---|---|---|
T |
| Type of elements of array |
Arguments
Arg | Type | Optional | Default | Description |
---|---|---|---|---|
arr | T[] | false | undefined | Array to be sorted |
comparator | (a: T, b: T) => number | true | undefined | Comparator for sorting |
Returns
Type |
---|
number[] |