Skip to content

Instantly share code, notes, and snippets.

@hebertcisco
Created May 23, 2020 05:31
Show Gist options
  • Save hebertcisco/259d481c5a4bd770efb41d29bc9ac96e to your computer and use it in GitHub Desktop.
Save hebertcisco/259d481c5a4bd770efb41d29bc9ac96e to your computer and use it in GitHub Desktop.
The reduce() method performs a reducing function (download for you) for each element of the matrix, resulting in a single return value.
const githubStars = [
{
userID: "tecnobert",
userStars: 88,
},
{
userID: "philipwalton",
userStars: 36,
},
{
userID: "cytopia",
userStars: 370,
},
];
const totalStars = githubStars.reduce((sum, stars) => {
return sum + stars.userStars;
}, 0);
console.log(totalStars);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment