Given an array of objects, return a new array sorted by the numerical property specified in the get function. A third, and optional, argument allows you to sort in descending order instead of the default ascending order.
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 _
_.
sort<{
name:string;
weight:number;
}>(array:readonly {
name:string;
weight:number;
}[], getter: (item: {
name:string;
weight:number;
}) =>number, desc?:boolean): {
name:string;
weight:number;
}[]
export sort
Sort an array without modifying it and return the newly sorted
value.