Skip to content

Instantly share code, notes, and snippets.

@ccavazos
Last active June 26, 2017 17:36
Show Gist options
  • Save ccavazos/8a5a82ba4f79594923e7 to your computer and use it in GitHub Desktop.
Save ccavazos/8a5a82ba4f79594923e7 to your computer and use it in GitHub Desktop.
Compare Objects Helper
/**
* Compares 2 Javascript Objects
* @compareObjects
* @param {Object} _old
* @param {Object} _new
* @return {Object} results
*/
exports.compareObjects = function(_old, _new) {
var diff;
if (_new == null || _new === "null"){
return null;
}
if (typeof(_new) === 'object') {
diff = {};
for (var _property in _new) {
if (_old.hasOwnProperty(_property)){
diff[_property] = exports.compareObjects(_old[_property], _new[_property]);
}else{
diff[_property] = exports.compareObjects(null, _new[_property]);
}
}
} else {
if (_old === _new) {
diff = false;
} else {
diff = true;
}
}
return diff;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment