Last active
August 2, 2018 21:43
-
-
Save funador/f42c99b5acb44168eae71b7ba409411b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| const vetApprovedDogs = [ | |
| {name: 'Snookums', needsShots: false, breed: 'pug', age: 2}, | |
| {name: 'Thor', needsShots: false, breed: 'hound', age: 1}, | |
| {name: 'Wunderbar', needsShots: false, breed: 'pug', age: 9}, | |
| ] | |
| // I need a little more practice with map! | |
| const allDogsAges = vetApprovedDogs.map(dog => dog.age) | |
| console.log(allDogsAges) // [2, 1, 9] | |
| // Next we need to get the total age of the dogs | |
| const totalAgeOfDogs = allDogsAges.myReduce((totalYears, dogAge) => { | |
| // This return statement adds the current dog's age to a collector | |
| // of all the previous dogs ages | |
| return totalYears + dogAge | |
| }) | |
| console.log(totalAgeOfDogs) // 12 | |
| // Thanks to my trusty Math skills I am able to get the city what it needs! | |
| const averageDogAge = totalAgeOfDogs / vetApprovedDogs.length | |
| console.log(averageDogAge) // 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment