12 lines
388 B
TypeScript
12 lines
388 B
TypeScript
/**
|
|
* Returns a filter lambda to be used in array.filter() to only allow the
|
|
* first occurrence of duplicate values.
|
|
* @param isEqual Custom equality check, defaults to `a === b`
|
|
*/
|
|
export function unique<E>(
|
|
isEqual: (a: E, b: E) => boolean = (a, b) => a === b
|
|
) {
|
|
return (self: E, index: number, arr: ReadonlyArray<E>) =>
|
|
arr.findIndex((v) => isEqual(v, self)) === index;
|
|
}
|