Skip to content

Instantly share code, notes, and snippets.

@ascott1
Created May 12, 2014 23:12
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 ascott1/ccfb745bc2d5a361b55f to your computer and use it in GitHub Desktop.
Save ascott1/ccfb745bc2d5a361b55f to your computer and use it in GitHub Desktop.
simple object comparison
var compare = function(a, b) {
"use strict";
// iterate over each key in b
for (var key in b) {
// check if the key is present in a
if (key in a) {
// make sure a and be are not exact matches
if (b[key] !== a[key]) {
c[key] = b[key]; // if not an exact match add to c
}
} else {
c[key] = b[key]; // if the key is not found add it to c
}
}
return c;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment