Skip to content

Instantly share code, notes, and snippets.

@gonejack
Last active February 25, 2016 08:30
Show Gist options
  • Save gonejack/af55f8659c7233606ac6 to your computer and use it in GitHub Desktop.
Save gonejack/af55f8659c7233606ac6 to your computer and use it in GitHub Desktop.
recursive compare
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