Created
March 10, 2014 11:14
-
-
Save CezaryDanielNowak/9463229 to your computer and use it in GitHub Desktop.
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
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