Last active
March 29, 2020 07:49
-
-
Save jkbockstael/445efe381e6c865f81a70999b5fe4885 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
// Equality | |
// equal :: a -> b -> boolean | |
function equal (a, b) { | |
if (typeof a !== typeof b) { | |
return false; | |
} | |
if (a === b) { | |
return true; | |
} | |
if (Array.isArray(a) && Array.isArray(b)) { | |
if (a.length !== b.length) { | |
return false; | |
} | |
for (var i in a) { | |
if (!equal(a[i], b[i])) { | |
return false; | |
} | |
} | |
return true; | |
} | |
if (Array.isArray(a) === !Array.isArray(b)) { | |
return false; | |
} | |
if (typeof a === 'object') { | |
for (var key in a) { | |
if (!equal(a[key], b[key])) { | |
return false; | |
} | |
} | |
return true; | |
} | |
return false; | |
} | |
// Curried equality | |
// equals :: a -> (b -> boolean) | |
function equals (a) { | |
return function (b) { | |
return equal(a, b); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment