From d8efba24e09aa2a8dbf028fc57a561a56e7833fd Mon Sep 17 00:00:00 2001 From: Suneet Tipirneni <77477100+suneettipirneni@users.noreply.github.com> Date: Tue, 11 Jan 2022 06:29:41 -0500 Subject: [PATCH] refactor: make `intersect` perform a true intersection (#7211) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Antonio Román --- packages/collection/src/index.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/collection/src/index.ts b/packages/collection/src/index.ts index 1ba5128b1..ed266aebd 100644 --- a/packages/collection/src/index.ts +++ b/packages/collection/src/index.ts @@ -625,14 +625,16 @@ export class Collection extends Map { } /** - * The intersect method returns a new structure containing items where the keys are present in both original structures. + * The intersect method returns a new structure containing items where the keys and values are present in both original structures. * * @param other The other Collection to filter against */ public intersect(other: Collection): Collection { const coll = new this.constructor[Symbol.species](); for (const [k, v] of other) { - if (this.has(k)) coll.set(k, v); + if (this.has(k) && Object.is(v, this.get(k))) { + coll.set(k, v); + } } return coll; }