diff --git a/filter1.js b/filter1.js index 602ddc0..fb3cf51 100644 --- a/filter1.js +++ b/filter1.js @@ -22,3 +22,4 @@ let people = [ let isCool = person => person.coolnessScore > 20 // Your code goes here +const coolPeople = people.filter(person => {return isCool(person)}) \ No newline at end of file diff --git a/filter2.js b/filter2.js index fd52f91..ab875c0 100644 --- a/filter2.js +++ b/filter2.js @@ -4,3 +4,4 @@ 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 noStrings = misc.filter(elem => {return typeof elem !== 'string'}) \ No newline at end of file diff --git a/foreach1.js b/foreach1.js index 7158aaa..0d383ff 100644 --- a/foreach1.js +++ b/foreach1.js @@ -9,3 +9,4 @@ let foods = ["pizza", "tacos", "ice cream", "sushi"]; // your code here +foods.forEach(food => {return console.log(`I like ${food}`)}) \ No newline at end of file diff --git a/foreach2.js b/foreach2.js index 7c29104..8f5ffbb 100644 --- a/foreach2.js +++ b/foreach2.js @@ -11,4 +11,4 @@ let foods = [ ]; // your code here - +foods.forEach(food => {return console.log(`${food.name} is ${food.level} delicious`)}) diff --git a/map1.js b/map1.js index 9ec71f4..00dd368 100644 --- a/map1.js +++ b/map1.js @@ -40,3 +40,8 @@ let forecast = [ // "Monday will have a high of 55F and a low of 53F." //Your code here +const stringForecasts = forecast.map(forecast => { + return `${forecast.day} will have a high of ${forecast.high}F and a low of ${forecast.low}F.` +}) + +console.log(stringForecasts) \ No newline at end of file diff --git a/map2.js b/map2.js index aa8ae04..5486efd 100644 --- a/map2.js +++ b/map2.js @@ -6,3 +6,8 @@ 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}) + +const largerNums = squaredNums.filter(num => {return num > 30}) + +largerNums.forEach(num => {return console.log(`${num} is larger than 30.`)}) \ No newline at end of file diff --git a/reduce.js b/reduce.js index 50a1791..5a604e2 100644 --- a/reduce.js +++ b/reduce.js @@ -6,6 +6,8 @@ const numbers = [1, 56, 2, 4, 1, 99, 3, 5] // via multiplication // Use reduce to get the sum of all the numbers +const multipliedSum = numbers.reduce((acc, curr) => {return acc * curr}) +console.log(multipliedSum) // Hungry for more: @@ -33,8 +35,18 @@ const cities = [ ] // Use reduce to get the sum of the population of all 5 cities +const popSum = cities.reduce((total, curr) => { + return total + curr.population +}, 0) +console.log(popSum) // Use reduce to get the city with the highest population (output should be an object) +// this doesn't work, no idea why! +const largestPop = cities.reduce((largest, current) => { + return largest +}) + +console.log(largestPop) // Even hungrier: @@ -49,8 +61,8 @@ const developers = [ { name: 'Maria', languages: [ - 'JavaScript', - 'Ruby' + 'JavaScript', + 'Ruby' ] }, { @@ -94,4 +106,4 @@ const developers = [ -// Instead of hardcoding the languages in your initial object, can you think of a way to do this programmatically? +// Instead of hardcoding the languages in your initial object, can you think of a way to do this programmatically? \ No newline at end of file