mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-14 02:23:31 +01:00
feat: add Collection#subtract() (#8393)
* feat: add `Collection#missing()` * test: add test for `Collection#missing()` * chore: rename `missing` to `complement` * docs: fix name * test: fix test name Co-authored-by: Almeida <almeidx@pm.me> * chore: sort alphabetically * fix: edit condition Co-authored-by: Almeida <almeidx@pm.me> * refactor: rename to `subtract` * docs: fix description Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> * fix: change condition * fix: resolved eslint formatting error Co-authored-by: Almeida <almeidx@pm.me> Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: Aura Román <kyradiscord@gmail.com>
This commit is contained in:
@@ -684,6 +684,22 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
return coll;
|
||||
}
|
||||
|
||||
/**
|
||||
* The subtract method returns a new structure containing items where the keys and values of the original structure are not present in the other.
|
||||
*
|
||||
* @param other - The other Collection to filter against
|
||||
*/
|
||||
public subtract<T>(other: ReadonlyCollection<K, T>): Collection<K, V> {
|
||||
const coll = new this.constructor[Symbol.species]<K, V>();
|
||||
for (const [k, v] of this) {
|
||||
if (!other.has(k) || !Object.is(v, other.get(k))) {
|
||||
coll.set(k, v);
|
||||
}
|
||||
}
|
||||
|
||||
return coll;
|
||||
}
|
||||
|
||||
/**
|
||||
* The difference method returns a new structure containing items where the key is present in one of the original structures but not the other.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user