mirror of
https://github.com/danbulant/discord.js
synced 2026-05-25 13:02:38 +00:00
equals function added (#948)
Adds an equals function that checks for differing size and differing key-value pairs, and takes into account the edge case for when there's an entry for the key, but the value is undefined.
This commit is contained in:
parent
a53dcd52e7
commit
a0b245bfe1
1 changed files with 16 additions and 0 deletions
|
|
@ -329,6 +329,22 @@ class Collection extends Map {
|
|||
}
|
||||
return returns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the collections have identical key-value pairings.
|
||||
* This is different to checking for equality using equal-signs, because
|
||||
* the collections may be different objects, but functionally identical.
|
||||
* @param {Collection} collection Collection to compare with.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
equals(collection) {
|
||||
if (this === collection) return true;
|
||||
if (this.size !== collection.size) return false;
|
||||
return !this.find((value, key) => {
|
||||
const testVal = collection.get(key);
|
||||
return testVal !== value || (testVal === undefined && !collection.has(key));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Collection;
|
||||
|
|
|
|||
Loading…
Reference in a new issue