From 4dbdb6a967f056a74ee14d57c1d0bee14af22671 Mon Sep 17 00:00:00 2001 From: Angus MacDonald Date: Fri, 27 Nov 2020 11:21:30 -0600 Subject: [PATCH] Add arrayf.subtract function --- src/arrayf/arrayf.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/arrayf/arrayf.ts b/src/arrayf/arrayf.ts index c53ee4696a..f6518927fd 100644 --- a/src/arrayf/arrayf.ts +++ b/src/arrayf/arrayf.ts @@ -28,5 +28,13 @@ export class arrayf { return output; } - -} \ No newline at end of file + /** + * Remove any elements that exist in the subtrahend from the minuend. + * ``` + * arrayf.subtract([1,2,3], [2,3]); // Returns [1] + * ``` + */ + static subtract(minuend: T[], subtrahend: T[]): T[] { + return minuend.filter((value) => subtrahend.indexOf(value) === -1); + } +}