i18n: Upgrade translations from crowdin (61e08dd5). (pass-desktop)
[ProtonMail-WebClient.git] / packages / utils / uniqueBy.ts
blob3118df058a3c6e4b9a3408f89b689cd7c85c0fb5
1 /**
2  * Extract the elements from an array that are unique according to a comparator function
3  */
4 const uniqueBy = <T>(array: T[], comparator: (t: T) => any) => {
5     const seen = new Set();
6     return array.filter((value) => {
7         const computed = comparator(value);
8         const hasSeen = seen.has(computed);
9         if (!hasSeen) {
10             seen.add(computed);
11         }
12         return !hasSeen;
13     });
16 export default uniqueBy;