From bcef42fe1fda66bf789646849be580f419a6f114 Mon Sep 17 00:00:00 2001 From: MathMan05 Date: Tue, 25 Nov 2025 23:54:33 -0600 Subject: [PATCH] remove distinct by --- src/util/util/extensions/Array.test.ts | 12 ------------ src/util/util/extensions/Array.ts | 22 ---------------------- 2 files changed, 34 deletions(-) diff --git a/src/util/util/extensions/Array.test.ts b/src/util/util/extensions/Array.test.ts index 1dea2cf43..effa38e4f 100644 --- a/src/util/util/extensions/Array.test.ts +++ b/src/util/util/extensions/Array.test.ts @@ -40,16 +40,4 @@ describe("Array extensions", () => { assert.deepEqual(arr.distinct(), [1, 2, 3]); assert.deepEqual([].distinct(), []); }); - - it("distinctBy", () => { - const arr = [{ id: 1 }, { id: 2 }, { id: 1 }, { id: 3 }]; - assert.deepEqual( - arr.distinctBy((x) => x.id), - [{ id: 1 }, { id: 2 }, { id: 3 }], - ); - assert.deepEqual( - [].distinctBy((x) => x), - [], - ); - }); }); diff --git a/src/util/util/extensions/Array.ts b/src/util/util/extensions/Array.ts index a5cda5711..2b80b0bc9 100644 --- a/src/util/util/extensions/Array.ts +++ b/src/util/util/extensions/Array.ts @@ -23,7 +23,6 @@ declare global { filterAsync(callback: (elem: T, index: number, array: T[]) => Promise): Promise; remove(item: T): void; distinct(): T[]; - distinctBy(key: (elem: T) => K): T[]; } } @@ -55,23 +54,6 @@ export function arrayDistinct(this: T[]): T[] { return Array.from(new Set(this)); } -export function arrayDistinctBy(this: T[], key: (elem: T) => K): T[] { - const seen = new Set(); - return this.filter((item) => { - const k = key(item); - if (seen.has(k)) { - return false; - } else { - seen.add(k); - return true; - } - }); -} - -export function arrayIntersect(this: T[], other: T[]): T[] { - return this.filter((value) => other.includes(value)); -} - // register extensions if (!Array.prototype.partition) Array.prototype.partition = function (this: T[], filter: (elem: T) => boolean) { @@ -95,7 +77,3 @@ if (!Array.prototype.distinct) Array.prototype.distinct = function (this: T[]) { return arrayDistinct.call(this); }; -if (!Array.prototype.distinctBy) - Array.prototype.distinctBy = function (this: T[], key: (elem: T) => K) { - return arrayDistinctBy.call(this, key as (elem: unknown) => unknown); - };