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 whoIsCool = people.filter(person => {
return person.coolnessScore > 20;
})
console.log(whoIsCool)
5 changes: 4 additions & 1 deletion filter2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ let misc = [3, "true", {a: 1, b: 2}, 7, [1, 2, 3], ['a', 'b', 'c'], "my favorite

// Use filter to filter all strings out of the above array.
// Don't worry about strings in the nested array (misc[5] is considered an array, not a string)

const allStrings = misc.filter((str) => {
return str.substring
})
// Your code goes here
console.log(allStrings)
5 changes: 5 additions & 0 deletions foreach1.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@
let foods = ["pizza", "tacos", "ice cream", "sushi"];

// your code here

const iLikeFoods = foods.filter((food) => {
return console.log("I like " + food)
})
console.log(iLikeFoods)
4 changes: 4 additions & 0 deletions foreach2.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ let foods = [
];

// your code here
const goodFoods = foods.forEach((food) => {
return console.log(`${food.name} is ${food.level} delicious`)
})
console.log(goodFoods)

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

//Your code here

const squareEachNumber = numbers.map(num => {
return Math.pow(num, 2)
})

console.log(squareEachNumber)



const largerThan30 = squareEachNumber.filter(overThirty => {
return overThirty > 30
})

console.log(largerThan30)
24 changes: 23 additions & 1 deletion reduce.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,15 @@ const cities = [

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

const addPopulation = cities.reduce((world, city) => {
return city.population + world ;
}, 0)
console.log(addPopulation)
// Use reduce to get the city with the highest population (output should be an object)

// const highestPopulation = cities.reduce((world, city) => {
// return city.population + world ;
// }, 0)
// console.log(addPopulation)
// Even hungrier:

const developers = [
Expand Down Expand Up @@ -86,6 +93,21 @@ const developers = [

// This one is HARD

// reduce has optional second argument
// this will stand for the initial value
// const ageSum = instructors.reduce((sum, instructor) => {
// return sum + instructor.age ;
// }, 0)

// console.log(ageSum)

// const makeSum = (num1, num2) => {
// return num1 + num2.age
// }
// const ageSum = instructors.reduce(makeSum, 0)
// console.log(ageSum)


// Hint 1: the desired output is an object, you might want to use that as your initial value


Expand Down