Skip to content

Instantly share code, notes, and snippets.

@dottedsquirrel
Created August 30, 2019 01:59
Show Gist options
  • Save dottedsquirrel/ec743056cf0609becbe9275c26127450 to your computer and use it in GitHub Desktop.
Save dottedsquirrel/ec743056cf0609becbe9275c26127450 to your computer and use it in GitHub Desktop.
JavaScript mix n match
let animals = [
{name: 'Tibbers', type: 'cat', isNeutered: true, age: 2, enteredPagent: true, cutenessScore: 347},
{name: 'Fluffball', type: 'rabbit', isNeutered: false, age: 1, enteredPagent: true, cutenessScore: 193},
{name: 'Strawhat', type: 'cat', isNeutered: true, age: 5, enteredPagent: false, cutenessScore: 521}
]
//lets say you want to find the total cuteness score of all valid pagent entrants
let totalScore = animals
.filter(animal => {return animal.isNeutered})
.reduce((accumulator, animal) => {return accumulator + animal.cutenessScore}, 0);
// totalScore will return 868
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment