Skip to content

Instantly share code, notes, and snippets.

@ross-u
Created October 7, 2019 16:21
Show Gist options
  • Save ross-u/a167ce8ac283c423cc8e45c99e897ead to your computer and use it in GitHub Desktop.
Save ross-u/a167ce8ac283c423cc8e45c99e897ead to your computer and use it in GitHub Desktop.
JS | Array methods - reduce()

JS | Array methods - reduce()

Age Reducer - Exercise


Using the reduce() method provided in the code below, add the age of each person object from the people array and console.log the ageTotal which should equal the sum of all the people's age.


Go ahead to Repl.it, using the code below as your starting point.

const people = [
{ name: "Candice", age: 25 },
{ name: "Tammy", age: 30 },
{ name: "Allen", age: 49 },
{ name: "Nettie", age: 21 },
{ name: "Stuart", age: 17 }
];
const ageTotal = people.reduce( (sum, person) => {
// Your Code here
});
console.log(ageTotal);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment