fn
unique
v0.0.3testedReturns a new array with unique values from the original array
Examples
ts
unique([1, 2, 3, 3, 4, 5, 5, 6]) //=> [1, 2, 3, 4, 5, 6]ts
unique([{ id: 1 }, { id: 2 }, { id: 1 }], value => value.id) //=> [{ id: 1 }, { id: 2 }]Signature
ts
export function unique<Value, Key extends UniqueKey>(
array: Value[],
extractor?: Extractor<Value, Key>,
): Value[]{ ... }Type Parameters
ValueKeyextends UniqueKeyParameters
| Parameter | Type | Description |
|---|---|---|
array | Value[] | The array to filter |
extractor? | Extractor<Value, Key> | undefined | The function to extract the value to compare |
Returns
Value[]- The new array with unique values