From 06a80b0d9d6c3f04dd9a096c597d83af23c633b0 Mon Sep 17 00:00:00 2001 From: Andy Sakai Date: Fri, 14 Aug 2020 20:03:19 -0700 Subject: [PATCH 1/2] Andy Sakai --- challenges/arrays-callbacks.js | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/challenges/arrays-callbacks.js b/challenges/arrays-callbacks.js index 12af878ceb..6db9454224 100644 --- a/challenges/arrays-callbacks.js +++ b/challenges/arrays-callbacks.js @@ -20,17 +20,27 @@ const zooAnimals = [ The zoos want to display both the scientific name and the animal name in front of the habitats. Populate the displayNames array with only the animal_name and scientific_name of each animal. displayNames will be an array of strings, and each string should follow this pattern: "Name: Jackal, asiatic, Scientific: Canis aureus." */ -const displayNames = []; -console.log(displayNames); +var displayNames = [] + + zooAnimals.forEach((names) => { + + displayNames.push(zooAnimals.animal_name + zooAnimals.scientific_name) + console.log(`Animal Name: ${names.animal_name}, Scientific Name: ${names.scientific_name}`)}); /* Request 2: .map() The zoos need a list of all their animal's names (animal_name only) converted to lower case. Using map, create a new array of strings named lowCaseAnimalNames, each string following this pattern: "jackal, asiatic". Log the resut. */ - const lowCaseAnimalNames = []; -console.log(lowCaseAnimalNames); + +zooAnimals.map((Aname,index) => { + + lowCaseAnimalNames.push(zooAnimals[index].animal_name); + + console.log(`Animal Name: ${Aname.animal_name.toLowerCase()}`) + } +); /* Request 3: .filter() @@ -38,6 +48,17 @@ The zoos are concerned about animals with a lower population count. Using filter */ const lowPopulationAnimals = []; + +zooAnimals.filter((pop) => { + + if (pop.population < 5); + { + lowPopulationAnimals.push(pop.animal_name); + } + + +}) + console.log(lowPopulationAnimals); /* Request 4: .reduce() From 4a4233aef8f6063411c173dbed1994b898941968 Mon Sep 17 00:00:00 2001 From: Andy Sakai Date: Fri, 14 Aug 2020 20:39:39 -0700 Subject: [PATCH 2/2] Array Methods done --- .vscode/launch.json | 17 +++++++++++++++++ challenges/arrays-callbacks.js | 17 ++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000000..b4ec085338 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,17 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "skipFiles": [ + "/**" + ], + "program": "${workspaceFolder}\\challenges\\arrays-callbacks.js" + } + ] +} \ No newline at end of file diff --git a/challenges/arrays-callbacks.js b/challenges/arrays-callbacks.js index 6db9454224..4d04af2fd8 100644 --- a/challenges/arrays-callbacks.js +++ b/challenges/arrays-callbacks.js @@ -65,8 +65,14 @@ console.log(lowPopulationAnimals); The zoos need to know their total animal population across the United States. Find the total population from all the zoos using the .reduce() method. Remember the reduce method takes two arguments: a callback (which itself takes two args), and an initial value for the count. + */ -let populationTotal = 0; + +let populationTotal = zooAnimals.reduce((total, zoo) => { +return total += zoo.population; + +}, 0) + console.log(populationTotal); @@ -79,6 +85,15 @@ console.log(populationTotal); * The consume function should return the invocation of cb, passing a and b into cb as arguments */ +function consume (a,b,cb) +{ + cb () + { + a = arg1; + b = arg2; + } + +} /* Step 2: Create several functions to callback with consume(); * Create a function named add that returns the sum of two numbers