Skip to content

Instantly share code, notes, and snippets.

@jkbockstael
Last active March 29, 2020 07:49
Show Gist options
  • Save jkbockstael/445efe381e6c865f81a70999b5fe4885 to your computer and use it in GitHub Desktop.
Save jkbockstael/445efe381e6c865f81a70999b5fe4885 to your computer and use it in GitHub Desktop.
// 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