From 8bd0d5c06b5c313388cb4eb5356475e803350d1a Mon Sep 17 00:00:00 2001 From: Rory& Date: Fri, 3 Oct 2025 20:30:45 +0200 Subject: [PATCH] Add Array.remove extension --- src/util/util/extensions/Array.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/util/util/extensions/Array.ts b/src/util/util/extensions/Array.ts index 32845b0c..53d26ed6 100644 --- a/src/util/util/extensions/Array.ts +++ b/src/util/util/extensions/Array.ts @@ -22,6 +22,7 @@ declare global { partition(filter: (elem: T) => boolean): [T[], T[]]; single(filter: (elem: T) => boolean): T | null; forEachAsync(callback: (elem: T, index: number, array: T[]) => Promise): Promise; + remove(item: T): void; } } @@ -48,6 +49,13 @@ export async function forEachAsync(array: T[], callback: (elem: T, index: num await Promise.all(array.map(callback)); } +export function remove(this: T[], item: T): void { + const index = this.indexOf(item); + if (index > -1) { + this.splice(index, 1); + } +} + // register extensions if (!Array.prototype.containsAll) Array.prototype.containsAll = function (this: T[], target: T[]) { @@ -65,3 +73,7 @@ if (!Array.prototype.forEachAsync) Array.prototype.forEachAsync = function (this: T[], callback: (elem: T, index: number, array: T[]) => Promise) { return forEachAsync(this, callback); }; +if (!Array.prototype.remove) + Array.prototype.remove = function (this: T[], item: T) { + return remove.call(this, item); + };