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

8 lines
274 B
TypeScript
Raw Normal View History

export const unique = <T extends string | number>(items: T[]): T[] =>
Array.from(new Set(items));
2023-03-14 16:27:57 +01:00
export const uniqueByKey = <T extends Record<string, unknown>>(
items: T[],
key: keyof T,
): T[] => [...new Map(items.map((item) => [item[key], item])).values()];