Skip to content

Instantly share code, notes, and snippets.

@jhwheeler
Created March 9, 2020 16:35
Show Gist options
  • Save jhwheeler/263627c77eb65ca44c588c8e08a63a83 to your computer and use it in GitHub Desktop.
Save jhwheeler/263627c77eb65ca44c588c8e08a63a83 to your computer and use it in GitHub Desktop.
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