Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions filter1.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 4 additions & 0 deletions filter2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 3 additions & 0 deletions foreach1.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@
let foods = ["pizza", "tacos", "ice cream", "sushi"];

// your code here
foods.forEach((food) => {
console.log(`I like ${food}`)
})
4 changes: 3 additions & 1 deletion foreach2.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ let foods = [
];

// your code here

foods.forEach((food) => {
console.log(`${food.name} is ${food.level} delicious`)
})
6 changes: 6 additions & 0 deletions map1.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
13 changes: 13 additions & 0 deletions map2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
})
17 changes: 15 additions & 2 deletions reduce.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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 = [
Expand Down