Last active
September 22, 2017 17:09
-
-
Save mcabreradev/019690a0e586d868db06b3335eeb44d0 to your computer and use it in GitHub Desktop.
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
let items = [ | |
{name:"A", value:2}, | |
{name:"B", value:3}, | |
{name:"A", value:4}, | |
]; | |
let result = []; | |
items.map((item, index) => { | |
let res = result.find(res => res.name === item.name); | |
if (res) { | |
res.value += item.value; | |
} else { | |
result.push(item); | |
} | |
}); | |
console.log(result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment