Created
August 30, 2019 01:59
-
-
Save dottedsquirrel/ec743056cf0609becbe9275c26127450 to your computer and use it in GitHub Desktop.
JavaScript mix n match
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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