1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-11-01 19:07:38 +01:00
unleash.unleash/src/lib/util/unique.ts
2023-03-14 16:27:57 +01:00

8 lines
274 B
TypeScript

export const unique = <T extends string | number>(items: T[]): T[] =>
Array.from(new Set(items));
export const uniqueByKey = <T extends Record<string, unknown>>(
items: T[],
key: keyof T,
): T[] => [...new Map(items.map((item) => [item[key], item])).values()];