Created
March 9, 2020 16:35
-
-
Save jhwheeler/263627c77eb65ca44c588c8e08a63a83 to your computer and use it in GitHub Desktop.
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
export function checkArrayElementsEquality (initialArray, comparedArray) { | |
if (!initialArray || !comparedArray) return false | |
if (initialArray.length !== comparedArray.length) return false | |
const superSet = {} | |
for (let i = 0; i < initialArray.length; i++) { | |
const element = initialArray[i] + typeof initialArray[i] | |
superSet[element] = 1 | |
} | |
for (let i = 0; i < comparedArray.length; i++) { | |
const element = comparedArray[i] + typeof comparedArray[i] | |
if (!superSet[element]) return false | |
superSet[element] = 2 | |
} | |
for (const element in superSet) { | |
if (superSet[element] === 1) return false | |
} | |
return true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment