Last active
February 25, 2016 08:30
-
-
Save gonejack/af55f8659c7233606ac6 to your computer and use it in GitHub Desktop.
recursive compare
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 recursiveCompare(a, b) { | |
if (!(a instanceof Object) && !(b instanceof Object)) { | |
return a === b; | |
} | |
else if (a instanceof Array && b instanceof Array) { | |
for (var i = 0, l = a.length; i < l; i++) { | |
if (recursiveCompare(a[i], b[i]) === false) { | |
return false; | |
} | |
} | |
return true; | |
} | |
else if (a instanceof Object && b instanceof Object) { | |
for (var prop in b) { | |
if (a.hasOwnProperty(prop) && b.hasOwnProperty(prop) && recursiveCompare(a[prop], b[prop]) === false) { | |
return false; | |
} | |
} | |
return true; | |
} | |
else { | |
return false; | |
} | |
} | |
var isSame = recursiveCompare(originValues, newValues); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment