Created
May 12, 2014 23:12
-
-
Save ascott1/ccfb745bc2d5a361b55f to your computer and use it in GitHub Desktop.
simple object comparison
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
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