Last active
September 2, 2016 03:15
-
-
Save stefanmaric/8e27b870c0461355e35e to your computer and use it in GitHub Desktop.
Recursive areEquivalents function.
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 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