Sprint challenge #3 - #371
Conversation
JohnJustinn
left a comment
There was a problem hiding this comment.
Very good work this week. You have classes and parameters down. Just review array methods and reference the code I've provided in this review.
|
|
||
| function multiply(a,b,cb){ | ||
| return cb(a*b) ; | ||
| } |
There was a problem hiding this comment.
An additional callback parameter (cb) does not need to be passed into these methods unless you will be passing another function into them at a later time.
function add(a, b) {
return a + b;
}
That is all that is necessary since these functions are being passed to consume.
|
|
||
| // The zoos need a list of all their animal's names converted to lower case. Create a new array named lowerCase and map over each name to convert them all to lower case. Log the resut. | ||
| let lowerCase = []; | ||
|
|
There was a problem hiding this comment.
Because .map creates an array, you can immediately use it as the variable and remove the brackets.
let lowerCase = zooAnimals.map(function(animalName) {
return animalName.animal_name.toLowerCase();
})
console.log(lowerCase);
Here you pass a parameter into map method, animalName (though you could call it anything). Use the "dot" binding to connect this parameter to the animal_name key. toLowerCase will then access every value on this key and make it lower case.
| console.log(populationTotal); No newline at end of file | ||
| populationTotal.push(zooAnimals[i].population); | ||
| const reducer=(accumalator, currentValue)=> accumalator + currentValue; | ||
| console.log(populationTotal.reduce(reducer)); No newline at end of file |
There was a problem hiding this comment.
Here it's the same concept as reduce will return an array, so you do not need the brackets. Pass animal, and total as parameters on the reduce method. You could call this anything as long as it makes sense. Then use that to iterate each animal in the list by referencing population. Reduce adds that to a single sum.
let populationTotal = zooAnimals.reduce(function(animal, total) {
return animal + total.population;
}, 0);
console.log(populationTotal);
No description provided.