Given an array, return a new array sorted either by the numerical property specified in the get function or the numerical value of its items if no get function is passed. A third, and optional, argument allows you to sort in descending order instead of the default ascending order.
The function preserves the original order of items with equal values.
This function only supports numerical sorting. For alphabetic sorting, see the alphabetical function.
import*as
import _
_from'radashi'
const
constfish: {
name:string;
weight:number;
}[]
fish= [
{
name: string
name: 'Marlin',
weight: number
weight: 105,
},
{
name: string
name: 'Bass',
weight: number
weight: 8,
},
{
name: string
name: 'Trout',
weight: number
weight: 13,
},
]
import _
_.
functionsort<{
name:string;
weight:number;
}[]>(array: {
name:string;
weight:number;
}[], getter?: (item: {
name:string;
weight:number;
}) =>number, desc?:boolean): {
name:string;
weight:number;
}[]
Sort an array without modifying it and return the newly sorted
value.