dashpresshq/dashpress

View on GitHub
src/shared/lib/array/uniq-by.ts

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
export function uniqBy<T>(list: T[], key: keyof T): T[] {
  const seen = new Set();
  return list.filter((item) => {
    const k = item[key];
    return seen.has(k) ? false : seen.add(k);
  });
}