Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

sum properties some objects when merge their

function combine() {
    let result = {};

    for (let i = 0; i < arguments.length; i++) {
        for (let key in arguments[i]) {
            result[key] != undefined ? result[key] = result[key] + arguments[i][key] :
                result[key] = arguments[i][key]
        }
    }

    return result;
}
 
PREVIOUS NEXT
Tagged: #sum #properties #objects #merge
ADD COMMENT
Topic
Name
1+3 =