1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-10-04 11:17:02 +02:00
unleash.unleash/frontend/src/utils/unique.ts
2024-05-27 15:36:24 +02: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()];