Skip to content

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

ArgTypeDescription
TType of elements of array

Arguments

ArgTypeOptionalDefaultDescription
arrT[]falseundefinedArray to be sorted
comparator(a: T, b: T) => numbertrueundefinedComparator for sorting

Returns

Type
number[]