From 1c1df0c4de42ead21681f33a7638e8c287c3dad4 Mon Sep 17 00:00:00 2001 From: nicholasjpaterno Date: Tue, 5 May 2020 21:15:57 -0400 Subject: [PATCH] Add difference method and static --- src/index.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/index.ts b/src/index.ts index 64f326f..ea2e5fb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -51,6 +51,18 @@ export default class MaFP extends Map { } return _difference; } + + static difference>(mapA: T, mapB: T): MaFP { + const _difference = MaFP.clone(mapA); + for (const elem of mapB) { + const entry = _difference.get(elem[0]); + if (entry && entry === elem[1]) { + _difference.delete(elem[0]); + } + } + return _difference; + } + private _map(fn: FnSig, op: (key: K, value: T) => void): void { this.forEach((val, key) => { op(key, fn(val, key, this)); @@ -272,6 +284,17 @@ export default class MaFP extends Map { } return _difference; } + + difference>(otherMap: T): MaFP { + const _difference = this.clone(); + for (const elem of otherMap) { + const entry = _difference.get(elem[0]); + if (entry && entry === elem[1]) { + _difference.delete(elem[0]); + } + } + return _difference; + } } interface KeyOrValue extends IterableIterator {