Created
October 31, 2013 16:11
-
-
Save apipkin/7252397 to your computer and use it in GitHub Desktop.
removes mismatches between object a and object b
This file contains hidden or 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 removeMismatch (objA, objB) { | |
var key, val; | |
for (key in objA) { | |
val = objA[key]; | |
if (!objB[key] || typeof objA[key] !== typeof objB[key]) { | |
delete objA[key]; | |
} else { | |
if (typeof objA[key] === 'object') { | |
removeMismatch(objA[key], objB[key]); | |
} else { | |
if (objA[key] !== objB[key]) { | |
delete objA[key]; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment