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

let coolio = people.filter(element => isCool(element))

console.log(coolio)
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

let stringFilter = misc.filter(element => typeof element != "string")

console.log(stringFilter)
2 changes: 2 additions & 0 deletions foreach1.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@
let foods = ["pizza", "tacos", "ice cream", "sushi"];

// your code here

foods.forEach(element => console.log("I like " + element))
2 changes: 2 additions & 0 deletions foreach2.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ let foods = [

// your code here

foods.forEach(element => console.log(`${element.name} is ${element. level} delicious`))

4 changes: 4 additions & 0 deletions map1.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ let forecast = [
// "Monday will have a high of 55F and a low of 53F."

//Your code here

let returnString = forecast.map((e) => `${e.day} will have a high of ${e.high} and a low of ${e.low}`)

console.log(returnString)
4 changes: 4 additions & 0 deletions map2.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]
// e.g. "36 is larger than 30"

//Your code here

let final = numbers.map((e) => e * e).filter((f) => f > 30)

final.forEach(element => console.log(element + " is greater than 30"))
33 changes: 32 additions & 1 deletion reduce.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ 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

let sum = numbers.reduce((sum, curr) => sum + curr)
console.log(sum)

// Use reduce to get the sum of all the numbers

// Hungry for more:
Expand Down Expand Up @@ -33,8 +36,23 @@ const cities = [
]

// Use reduce to get the sum of the population of all 5 cities
console.log(
cities.reduce((sum, curr) => {
return sum + curr.population
}, 0)
)

// Use reduce to get the city with the highest population (output should be an object)
console.log(
cities.reduceRight((sum, curr) => {
if(curr.population > sum.population) {
return curr
}
else{
return sum
}
},cities[0])
)

// Even hungrier:

Expand Down Expand Up @@ -87,7 +105,20 @@ const developers = [
// This one is HARD

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

console.log(
developers.reduce((sum, curr) => {
for(let i = 0;i < curr.languages.length; i++){
let currentLang = curr.languages[i]
if (sum.hasOwnProperty(currentLang)){
sum[currentLang] = sum[currentLang] + 1
}
else{
sum[currentLang] = 1
}
}
return sum
}, {})
)


// Hint 2: Each developer's languages is stored in an array. You might need to iterate over it.
Expand Down