summaryrefslogtreecommitdiff
path: root/packages/client/src/scripts/array.ts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2022-03-09 23:04:16 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2022-03-09 23:04:16 +0900
commit6fc35868ff89c51720aad6e13676d10aa0785cf8 (patch)
treefa53821e51401b4c6283c8482452bc52d4f26834 /packages/client/src/scripts/array.ts
parentMerge branch 'develop' (diff)
parent12.108.0 (diff)
downloadmisskey-6fc35868ff89c51720aad6e13676d10aa0785cf8.tar.gz
misskey-6fc35868ff89c51720aad6e13676d10aa0785cf8.tar.bz2
misskey-6fc35868ff89c51720aad6e13676d10aa0785cf8.zip
Merge branch 'develop'
Diffstat (limited to 'packages/client/src/scripts/array.ts')
-rw-r--r--packages/client/src/scripts/array.ts11
1 files changed, 11 insertions, 0 deletions
diff --git a/packages/client/src/scripts/array.ts b/packages/client/src/scripts/array.ts
index d63f0475d0..29d027de14 100644
--- a/packages/client/src/scripts/array.ts
+++ b/packages/client/src/scripts/array.ts
@@ -52,6 +52,17 @@ export function unique<T>(xs: T[]): T[] {
return [...new Set(xs)];
}
+export function uniqueBy<TValue, TKey>(values: TValue[], keySelector: (value: TValue) => TKey): TValue[] {
+ const map = new Map<TKey, TValue>();
+
+ for (const value of values) {
+ const key = keySelector(value);
+ if (!map.has(key)) map.set(key, value);
+ }
+
+ return [...map.values()];
+}
+
export function sum(xs: number[]): number {
return xs.reduce((a, b) => a + b, 0);
}