numberSort
Sorts parameter arr numerically based on the order specified by parameter order with the default of 'asc'.
The parameter order can be specified as either 'asc' (ascending order) or 'desc' (descending order).
It will call numberComparatorAsc or numberComparatorDesc internally.
The optional parameter getter is used to obtain the numerical value from elements of arr, with the default being to use the element itself for sorting.
getter can be a field path of getByPath or a callback function.
Added in v0.0.2
Usage
ts
// UsageAPI
Type Parameter
| Arg | Type | Description |
|---|---|---|
T | | Type of elements of array |
R | extends 'asc' | 'desc' = 'asc' | 'desc' | Type of order for sorting |
Arguments
| Arg | Type | Optional | Default | Description |
|---|---|---|---|---|
arr | T[] | false | undefined | Array to be sorted |
order | R | false | undefined | Order for sorting |
getter | string | ((item: T) => number) | false | undefined | For extracting numerical values from array elements |
Returns
| Type |
|---|
T[] |