Skip to content

Commit bec1822

Browse files
halfway point
1 parent 6f1c7f8 commit bec1822

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

04 - Array Cardio Day 1/index-START.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,40 @@
3232
// Array.prototype.filter()
3333
// 1. Filter the list of inventors for those who were born in the 1500's
3434

35+
const fifteen = inventors.filter(inventor => inventor.year >= 1500 && inventor.year < 1600)
36+
console.table(fifteen);
37+
3538
// Array.prototype.map()
3639
// 2. Give us an array of the inventors' first and last names
3740

41+
const fullNames = inventors.map(inventor => `${inventor.first} ${inventor.last}`)
42+
console.log(fullNames)
43+
3844
// Array.prototype.sort()
3945
// 3. Sort the inventors by birthdate, oldest to youngest
46+
const ordered = inventors.sort((a, b) => a.year > b.year ? 1 : -1)
47+
console.table(ordered)
4048

4149
// Array.prototype.reduce()
4250
// 4. How many years did all the inventors live?
4351

52+
const totalYears = inventors.reduce((total, inventor) => {return total + (inventor.passed - inventor.year)}, 0)
53+
console.log(totalYears)
54+
4455
// 5. Sort the inventors by years lived
4556

57+
const oldest = inventors.sort(function(a, b) {
58+
const lastGuy = a.passed - a.year
59+
const nextGuy = b.passed - b.year
60+
61+
return lastGuy > nextGuy ? -1 : 1
62+
})
63+
console.table(oldest)
64+
4665
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
4766
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
4867

68+
4969

5070
// 7. sort Exercise
5171
// Sort the people alphabetically by last name

0 commit comments

Comments
 (0)