Skip to content

Instantly share code, notes, and snippets.

@mcabreradev
Last active September 22, 2017 17:09
Show Gist options
  • Save mcabreradev/019690a0e586d868db06b3335eeb44d0 to your computer and use it in GitHub Desktop.
Save mcabreradev/019690a0e586d868db06b3335eeb44d0 to your computer and use it in GitHub Desktop.
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