Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

unique-by.ts

3 lines146 Bytes

1export function uniqueBy<T>(arr: T[], fn: (x: T) => unknown): T[] {
2 return arr.filter((x, i, a) => a.findIndex((y) => fn(x) === fn(y)) === i)
3}