Skip to content

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
// Usage

API

Type Parameter

ArgTypeDescription
TType of elements of array
Rextends 'asc' | 'desc' = 'asc' | 'desc'Type of order for sorting

Arguments

ArgTypeOptionalDefaultDescription
arrT[]falseundefinedArray to be sorted
orderRfalseundefinedOrder for sorting
getterstring | ((item: T) => number)falseundefinedFor extracting numerical values from array elements

Returns

Type
T[]