mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 12:03:31 +01:00
fix(Util): make arraysEqual avoid mutating the input arrays (#3506)
This commit is contained in:
@@ -84,9 +84,9 @@ class Util {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the arrays are equal, also removes duplicated entries from b.
|
* Checks whether two arrays are equal or have the same elements.
|
||||||
* @param {Array<*>} a Array which will not be modified.
|
* @param {Array<*>} a The first array.
|
||||||
* @param {Array<*>} b Array to remove duplicated entries from.
|
* @param {Array<*>} b The second array.
|
||||||
* @returns {boolean} Whether the arrays are equal.
|
* @returns {boolean} Whether the arrays are equal.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
@@ -94,12 +94,10 @@ class Util {
|
|||||||
if (a === b) return true;
|
if (a === b) return true;
|
||||||
if (a.length !== b.length) return false;
|
if (a.length !== b.length) return false;
|
||||||
|
|
||||||
for (const item of a) {
|
const setA = new Set(a);
|
||||||
const ind = b.indexOf(item);
|
const setB = new Set(b);
|
||||||
if (ind !== -1) b.splice(ind, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return b.length === 0;
|
return a.every(e => setB.has(e)) && b.every(e => setA.has(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user