Created
March 6, 2024 19:44
-
-
Save saintsGrad15/b67ce8e40f0c8f088104475402be4081 to your computer and use it in GitHub Desktop.
Shallowly compare the value equality of an Array.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function areArraysEqual(a, b) { | |
if (!Array.isArray(a) || !Array.isArray(b)) { throw new Error("At least one argument is not an Array."); } | |
if (a === b) { return true; } | |
if (a.length !== b.length) { return false; } | |
for (let i = 0; i < a.length; i++) { | |
if (a[i] !== b[i]) { | |
return false; | |
} | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment