Skip to content

Instantly share code, notes, and snippets.

@CezaryDanielNowak
Created March 10, 2014 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CezaryDanielNowak/9463229 to your computer and use it in GitHub Desktop.
Save CezaryDanielNowak/9463229 to your computer and use it in GitHub Desktop.
function compareObjects(o1, o2) {
var diff = {
'+':[], // fields exists in o1, but not in o2
'-':[] //fields exists in o2, but not in o1
};
for(var x in o1) {
if(o1.hasOwnProperty(x) && !o2.hasOwnProperty(x)) {
diff['+'].push(x);
}
}
for(var x in o2) {
if(o2.hasOwnProperty(x) && !o1.hasOwnProperty(x)) {
diff['-'].push(x);
}
}
return diff;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment