Skip to content

Sprint challenge #3 - #371

Open
RockmanExe wants to merge 1 commit into
bloominstituteoftechnology:masterfrom
RockmanExe:master
Open

Sprint challenge #3#371
RockmanExe wants to merge 1 commit into
bloominstituteoftechnology:masterfrom
RockmanExe:master

Conversation

@RockmanExe

Copy link
Copy Markdown

No description provided.

@JohnJustinn JohnJustinn left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread challenges/functions.js

function multiply(a,b,cb){
return cb(a*b) ;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 = [];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants