Skip to content

Commit d8efba2

Browse files
refactor: make intersect perform a true intersection (#7211)
Co-authored-by: Antonio Román <[email protected]>
1 parent 9052e32 commit d8efba2

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Diff for: packages/collection/src/index.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -625,14 +625,16 @@ export class Collection<K, V> extends Map<K, V> {
625625
}
626626

627627
/**
628-
* The intersect method returns a new structure containing items where the keys are present in both original structures.
628+
* The intersect method returns a new structure containing items where the keys and values are present in both original structures.
629629
*
630630
* @param other The other Collection to filter against
631631
*/
632632
public intersect<T>(other: Collection<K, T>): Collection<K, T> {
633633
const coll = new this.constructor[Symbol.species]<K, T>();
634634
for (const [k, v] of other) {
635-
if (this.has(k)) coll.set(k, v);
635+
if (this.has(k) && Object.is(v, this.get(k))) {
636+
coll.set(k, v);
637+
}
636638
}
637639
return coll;
638640
}

0 commit comments

Comments
 (0)