Skip to content

Instantly share code, notes, and snippets.

@stefanmaric
Last active September 2, 2016 03:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefanmaric/8e27b870c0461355e35e to your computer and use it in GitHub Desktop.
Save stefanmaric/8e27b870c0461355e35e to your computer and use it in GitHub Desktop.
Recursive areEquivalents function.
function areEquivalents (a, b) {
if (a && b && typeof a === 'object' && typeof a === typeof b && a.length === b.length) {
for (var prop in a) {
if (a.hasOwnProperty(prop) && !areEquivalents(a[prop], b[prop])) {
return false
}
}
for (var prop in b) {
if (b.hasOwnProperty(prop) && !areEquivalents(b[prop], a[prop])) {
return false
}
}
} else if (Number.isNaN(a) && Number.isNaN(b)) {
return true
} else if (a !== b) {
return false
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment