Last active
December 17, 2015 16:49
-
-
Save MattSurabian/5641223 to your computer and use it in GitHub Desktop.
merge objects function found on stack overflow. Modified *slightly* http://stackoverflow.com/questions/12208405/how-to-extend-2-objects-by-adding-numerical-values-together-from-keys-with-the
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
mergeObjects: function(){ | |
var mergedObj = {}; | |
for (var i = 0, max=arguments.length; i !== max; i++) { | |
var obj = arguments[i]; | |
for (var key in obj) { | |
if( obj.hasOwnProperty(key) ) { | |
if( mergedObj[key] ) { | |
mergedObj[key] += obj[key] | |
} | |
else { | |
mergedObj[key] = obj[key]; | |
} | |
} | |
} | |
} | |
return mergedObj; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment