/array/uniqueBy
stdFilters out duplicated values based on the result of the given key selector.
Type signature
<T, TResult>(f: (x: T) => TResult) => (xs: T[]) => T[]
Examples
uniqueBy(({ id }) => id)([
{ id: 1, value: "a" },
{ id: 2, value: "b" },
{ id: 1, value: "c" },
]);
// ⇒ [{ id: 1, value: 'c' }, { id: 2, value: 'b' }]
Try in REPL
Questions
- How to find all unique values in an array by some predicate?