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
6 changes: 5 additions & 1 deletion filter1.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ let people = [

let isCool = person => person.coolnessScore > 20

// Your code goes here
const coolList = people.filter((person) => {
return (isCool(person))
})

console.log(coolList)
6 changes: 6 additions & 0 deletions filter2.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ 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

let strings = misc.filter((newVal) => {
return typeof(newVal) !== "string"
})

console.log(strings)
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((foodILike) => {
console.log(`I like ${foodILike}`)
})
3 changes: 3 additions & 0 deletions foreach2.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ let foods = [

// your code here

foods.forEach((food) => {
console.log(`${food.name} is ${food.level} delicious`)
})
3 changes: 3 additions & 0 deletions map1.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ let forecast = [
// "Monday will have a high of 55F and a low of 53F."

//Your code here
const stringArr = forecast.map((eachFor) => {
console.log(`${eachFor.day} will have a high of ${eachFor.high} and a low of ${eachFor.low}.`)
})
11 changes: 11 additions & 0 deletions map2.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,14 @@ let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]
// e.g. "36 is larger than 30"

//Your code here

const squared = numbers.map((numSquared) => {
return numSquared * numSquared
})

const largerThanThirty = squared.map((big) => {
if (big > 30){
console.log(`${big} is larger than 30`)
}
})

25 changes: 23 additions & 2 deletions reduce.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
const numbers = [1, 56, 2, 4, 1, 99, 3, 5]

// Your code here!

const numSum = numbers.reduce((total, current) => {
return total + current
})
console.log(numSum)
// Write something that takes the above array and returns the product of all the numbers
// via multiplication

const numProd = numbers.reduce((total, current) => {
return total * current
})
console.log(numProd)
// Use reduce to get the sum of all the numbers




// Hungry for more:

const cities = [
Expand All @@ -32,8 +41,20 @@ const cities = [
}
]

const totalPop = cities.reduce((total, current) => {
return total + current.population
}, 0)
console.log(totalPop)



// Use reduce to get the sum of the population of all 5 cities



const biggest = cities.reduce((total, current) => {

}, 0)
// Use reduce to get the city with the highest population (output should be an object)

// Even hungrier:
Expand Down