@tempots/std
rankArray() function
Assigns ranks to the elements in the array based on the provided compare function. The ranks are assigned in ascending order, with the lowest value receiving a rank of 0. If there are duplicate values, the rank of the duplicates can be incremented or not based on the incrementDuplicates
parameter.
Signature:
rankArray: (array: T[], compare: (a: T, b: T) => number, incrementDuplicates?: boolean) => number[]
Parameters
Parameter |
Type |
Description |
---|---|---|
array |
T[] |
The array to rank. |
compare |
(a: T, b: T) => number |
The compare function used to determine the order of elements. |
incrementDuplicates |
boolean |
(Optional) Whether to increment the rank of duplicate values. |
Returns: number[]
An array of ranks corresponding to the elements in the input array.