Created
August 3, 2020 06:16
-
-
Save pzi/8c77c58f005718bbf01b55e9f9b6c121 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 isEqualArray(a, b) { | |
if (a === b) return true | |
if (a == null || b == null) return a !== a && b !== b | |
if (a.length !== b.length) return false | |
const aHasB = a.every(aValue => b.includes(aValue)) | |
const bHasA = b.every(bValue => a.includes(bValue)) | |
return aHasB && bHasA | |
} | |
isEqualArray([1], undefined) // false | |
isEqualArray(undefined, undefined) // true | |
isEqualArray(null, undefined) // false | |
isEqualArray(null, [1]) // false | |
isEqualArray(undefined, [1]) // false | |
isEqualArray([1], [1]) // true | |
isEqualArray([1], [1, 2]) // false | |
isEqualArray([1, 2], [1]) // false | |
isEqualArray([1, 2], [1, undefined]) // false | |
isEqualArray([1, undefined], [1, undefined]) // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment