Skip to content

Commit

Permalink
✨ - feat: add distinctArray utility
Browse files Browse the repository at this point in the history
  • Loading branch information
svenvandescheur committed Apr 8, 2024
1 parent cfb7351 commit e6bd9bf
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/lib/format/array.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/**
* Returns `array` with duplicates removed.
* Values are considered duplicate if `key` matches.
* @param array
* @param key
*/
export const distinctArray = <T = unknown[]>(array: T[], key: keyof T) => [
...new Map(array.map((value) => [value[key], value])).values(),
];

/**
* Returns `value` as `Array`.
* - If `value` is `undefined`, do nothing.
Expand Down

0 comments on commit e6bd9bf

Please sign in to comment.