Given an array of items — and optionally, a function to determine their identity — return a new array without any duplicates.
The function does not preserve the original order of items.
import*as
import _
_from'radashi'
const
constfish: {
name:string;
weight:number;
source:string;
}[]
fish= [
{
name: string
name: 'Marlin',
weight: number
weight: 105,
source: string
source: 'ocean',
},
{
name: string
name: 'Salmon',
weight: number
weight: 22,
source: string
source: 'river',
},
{
name: string
name: 'Salmon',
weight: number
weight: 22,
source: string
source: 'river',
},
]
import _
_.
unique<{
name:string;
weight:number;
source:string;
}, string>(array:readonly {
name:string;
weight:number;
source:string;
}[], toKey?: ((item: {
name:string;
weight:number;
source:string;
}) =>string) |undefined): {
name:string;
weight:number;
source:string;
}[]
export unique
Given a list of items returns a new list with only unique items.
Accepts an optional identity function to convert each item in the
list to a comparable identity value.