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
1 change: 1 addition & 0 deletions filter1.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ let people = [
let isCool = person => person.coolnessScore > 20

// Your code goes here
const coolPeople = people.filter(person => {return isCool(person)})
1 change: 1 addition & 0 deletions filter2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'})
1 change: 1 addition & 0 deletions foreach1.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
let foods = ["pizza", "tacos", "ice cream", "sushi"];

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

// your code here

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

Expand Down Expand Up @@ -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:

Expand All @@ -49,8 +61,8 @@ const developers = [
{
name: 'Maria',
languages: [
'JavaScript',
'Ruby'
'JavaScript',
'Ruby'
]
},
{
Expand Down Expand Up @@ -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?