1 export const duplicates = <T>(arr: T[]) =>
2 arr.reduce<Map<T, number>>((acc, item) => acc.set(item, (acc.get(item) ?? 0) + 1), new Map());
4 /** Removes duplicates from an array based on the provided equality function.
5 * This function is suitable for relatively "small" arrays. */
6 export const deduplicate = <T>(arr: T[], eq: (a: T) => (b: T) => boolean): T[] =>
7 arr.filter((a, idx) => arr.findIndex((b) => eq(a)(b)) === idx);