Last active
June 26, 2017 17:36
-
-
Save ccavazos/8a5a82ba4f79594923e7 to your computer and use it in GitHub Desktop.
Compare Objects Helper
This file contains 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
/** | |
* 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