From d02c303afd84b3c05970379242db6b237b8c3305 Mon Sep 17 00:00:00 2001 From: Kyra Date: Tue, 29 May 2018 11:15:19 +0200 Subject: [PATCH] fix(Guild): equals method modifying features array of guild (#2544) * Fixed a bug where Guild#equals would cause the given guild to lose its features * Fix Util.arraysEqual * Fixed docs for Util.arraysEqual * Remove Util.arraysEqual --- src/structures/Guild.js | 7 +++++-- src/util/Util.js | 19 ------------------- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/src/structures/Guild.js b/src/structures/Guild.js index d60927e0c..cbd5eacbd 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -944,10 +944,13 @@ class Guild extends Base { this.memberCount === guild.memberCount && this.large === guild.large && this.icon === guild.icon && - Util.arraysEqual(this.features, guild.features) && this.ownerID === guild.ownerID && this.verificationLevel === guild.verificationLevel && - this.embedEnabled === guild.embedEnabled; + this.embedEnabled === guild.embedEnabled && + (this.features === guild.features || ( + this.features.length === guild.features.length && + this.features.every((feat, i) => feat === guild.features[i])) + ); if (equal) { if (this.embedChannel) { diff --git a/src/util/Util.js b/src/util/Util.js index 5fe1b9a44..798db4991 100644 --- a/src/util/Util.js +++ b/src/util/Util.js @@ -118,25 +118,6 @@ class Util { return { animated: Boolean(m[1]), name: m[2], id: m[3] }; } - /** - * Checks whether the arrays are equal, also removes duplicated entries from b. - * @param {Array<*>} a Array which will not be modified. - * @param {Array<*>} b Array to remove duplicated entries from. - * @returns {boolean} Whether the arrays are equal. - * @private - */ - static arraysEqual(a, b) { - if (a === b) return true; - if (a.length !== b.length) return false; - - for (const item of a) { - const ind = b.indexOf(item); - if (ind !== -1) b.splice(ind, 1); - } - - return b.length === 0; - } - /** * Shallow-copies an object with its class/prototype intact. * @param {Object} obj Object to clone