Skip to content

Instantly share code, notes, and snippets.

@santiblanko
Last active August 9, 2016 18:23
Show Gist options
  • Select an option

  • Save santiblanko/8312e29e28a634576173ab06232386ba to your computer and use it in GitHub Desktop.

Select an option

Save santiblanko/8312e29e28a634576173ab06232386ba to your computer and use it in GitHub Desktop.
var people = [{
name:"santiago",
age:25,
country:"españa"
},{
name:"la",
age:23,
country:"colombia"
},{
name:"juan",
age:29,
country:"colombia"
}]
people.reduce(function(sum, current){
return sum + current.age
},0)
people.reduce(function(groupedByObject, current){
let country = current.country;
if(!groupedByObject[country])
groupedByObject[country] = 0;
groupedByObject[country] += current.age;
return groupedByObject;
}, {})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment