sort
@guoba-ai/utils / array / sort
Function: sort()
function sort<T>(
array,
fn,
desc?): T[];Defined in: array.ts:167
Sort an array by a derived numeric value. Returns a new array.
Type Parameters
T
T
Parameters
array
T[]
The array to sort
fn
(item) => number
Function that maps each item to a number for comparison
desc?
boolean
If true, sort in descending order
Returns
T[]
A new sorted array
Example
sort([3, 1, 2], v => v) // [1, 2, 3]
sort([3, 1, 2], v => v, true) // [3, 2, 1]