From 78ad78fd08c92ffc14c20a665e9ea6ec6008ddc9 Mon Sep 17 00:00:00 2001 From: "lyndonna.munro@gmail.com" Date: Tue, 14 Jun 2022 14:04:12 -0400 Subject: [PATCH] Working on the hungry for more --- filter1.js | 4 ++++ filter2.js | 4 ++++ foreach1.js | 3 +++ foreach2.js | 4 +++- map1.js | 6 ++++++ map2.js | 13 +++++++++++++ reduce.js | 17 +++++++++++++++-- 7 files changed, 48 insertions(+), 3 deletions(-) diff --git a/filter1.js b/filter1.js index 602ddc0..186fdf4 100644 --- a/filter1.js +++ b/filter1.js @@ -22,3 +22,7 @@ let people = [ let isCool = person => person.coolnessScore > 20 // Your code goes here +const coolness = people.filter((person) => { + return person.coolnessScore > 20 +}) +console.log(coolness) \ No newline at end of file diff --git a/filter2.js b/filter2.js index fd52f91..e4f6217 100644 --- a/filter2.js +++ b/filter2.js @@ -4,3 +4,7 @@ let misc = [3, "true", {a: 1, b: 2}, 7, [1, 2, 3], ['a', 'b', 'c'], "my favorite // Don't worry about strings in the nested array (misc[5] is considered an array, not a string) // Your code goes here +const stringsInArray = misc.filter((element) => { + return element.substring +}) +console.log(stringsInArray) diff --git a/foreach1.js b/foreach1.js index 7158aaa..5a9cb78 100644 --- a/foreach1.js +++ b/foreach1.js @@ -9,3 +9,6 @@ let foods = ["pizza", "tacos", "ice cream", "sushi"]; // your code here +foods.forEach((food) => { + console.log(`I like ${food}`) +}) \ No newline at end of file diff --git a/foreach2.js b/foreach2.js index 7c29104..5bc1c4a 100644 --- a/foreach2.js +++ b/foreach2.js @@ -11,4 +11,6 @@ let foods = [ ]; // your code here - +foods.forEach((food) => { + console.log(`${food.name} is ${food.level} delicious`) +}) diff --git a/map1.js b/map1.js index 9ec71f4..7aa020b 100644 --- a/map1.js +++ b/map1.js @@ -40,3 +40,9 @@ let forecast = [ // "Monday will have a high of 55F and a low of 53F." //Your code here +const forecastSentences = forecast.map((temp) => { + + return `${temp.day} will have a high of ${temp.high}F and a low of ${temp.low}F` + +}) +console.log(forecastSentences) \ No newline at end of file diff --git a/map2.js b/map2.js index aa8ae04..f8f297b 100644 --- a/map2.js +++ b/map2.js @@ -6,3 +6,16 @@ let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9] // e.g. "36 is larger than 30" //Your code here +const squaredNums = numbers.map((num) => { + return num*num +}) +console.log(squaredNums) + +const filteredNums = squaredNums.filter((num) => { + return num > 30 +}) +console.log(filteredNums) + +filteredNums.forEach((num) => { + console.log(`${num} is larger than 30`) +}) diff --git a/reduce.js b/reduce.js index 50a1791..f675ce2 100644 --- a/reduce.js +++ b/reduce.js @@ -4,9 +4,16 @@ const numbers = [1, 56, 2, 4, 1, 99, 3, 5] // Write something that takes the above array and returns the product of all the numbers // via multiplication +const product = numbers.reduce((acc, current) => { + return acc * current +}) +console.log(product) // Use reduce to get the sum of all the numbers - +const sum = numbers.reduce((acc, current) => { + return acc + current +}) +console.log(sum) // Hungry for more: const cities = [ @@ -33,9 +40,15 @@ const cities = [ ] // Use reduce to get the sum of the population of all 5 cities +const popSum = cities.reduce((sum, city) => { + return sum + city.population +}, 0) +console.log(popSum) // Use reduce to get the city with the highest population (output should be an object) - +const highestPop = cities.reduce((high, ) => { + +}) // Even hungrier: const developers = [