mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
refactor: make intersect perform a true intersection (#7211)
Co-authored-by: Antonio Román <kyradiscord@gmail.com>
This commit is contained in:
@@ -625,14 +625,16 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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<T>(other: Collection<K, T>): Collection<K, T> {
|
||||
const coll = new this.constructor[Symbol.species]<K, T>();
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user