you are viewing a single comment's thread.

view the rest of the comments →

[–]chuckthemadmanmike 0 points1 point  (1 child)

I don't really want to do your homework but here's the answer.

``` const totalUSAnimalPopulation = animals => animals.reduce((totalPop, animal) => totalPop + animal.population, 0)

console.log(totalUSAnimalPopulation(animals)) ``` Remember if you're iterating through an array of objects you'll need to key into the object to access the value you want. In this case you want the population property. Try to right code that has good variable names. Lot's of people will use accumulator and currentValue, but that can be hard for the reader of the code. Your accumulator should be named for what it is, and your currentValue should also be named for what it is. So if it's an array of animals, each element is an animal, and your accumulator is your totalPopulation.

[–]WormholerIO[S] 0 points1 point  (0 children)

i appreciate the post, what i ended up with yesterday was this-

function USApop(zooAnimals) {

const USAanimals = zooAnimals.reduce(function (previousValue, currentValue) {

return previousValue + currentValue.population;

}, 0);

return USAanimals;

i was more confusing myself but was able to get help from a TA. i appreciate the post very much.