R
fn

unique

v0.0.3tested

Returns 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

Value
Keyextends UniqueKey

Parameters

ParameterTypeDescription
arrayValue[]The array to filter
extractor?Extractor<Value, Key> | undefinedThe function to extract the value to compare

Returns

Value[]- The new array with unique values