Created
April 9, 2016 18:07
-
-
Save sebjwallace/c204138cf203bd30799bd36171c5a005 to your computer and use it in GitHub Desktop.
Shallow merge objects without overwriting or mutation
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 mergeObjects(merger,mergee){ | |
var mergent = {}; | |
for(var prop in mergee){ | |
mergent[prop] = mergee[prop] | |
} | |
for(prop in merger){ | |
if(mergent[prop]) | |
mergent[prop] = mergeObjects(mergent[prop],merger[prop]) | |
else mergent[prop] = merger[prop] | |
} | |
return mergent; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment