Skip to content

Commit b4faf6e

Browse files
author
William Coleman
authored
Merge pull request #9 from wcski/array-cardio-1
fArray cardio 1
2 parents 191e41f + 6fe424f commit b4faf6e

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636

3737
// Array.prototype.filter()
3838
// 1. Filter the list of inventors for those who were born in the 1500's
39-
//const fifteen = inventors.filter(inventor => inventor.year >= 1500 && inventor.year < 1600);
40-
//console.table(fifteen);
39+
const fifteen = inventors.filter(inventor => inventor.year >= 1500 && inventor.year < 1600);
40+
console.table(fifteen);
4141

4242
// Array.prototype.map()
4343
// 2. Give us an array of the inventors' first and last names
@@ -46,11 +46,20 @@
4646

4747
// Array.prototype.sort()
4848
// 3. Sort the inventors by birthdate, oldest to youngest
49+
const sorted = inventors.sort((a, b) => a.year > b.year ? 1 : -1);
50+
console.table(sorted);
51+
4952

5053
// Array.prototype.reduce()
5154
// 4. How many years did all the inventors live?
55+
const totalYears = inventors.reduce((total, inventor) => {
56+
return total + (inventor.passed - inventor.year);
57+
}, 0);
58+
console.log(totalYears);
5259

5360
// 5. Sort the inventors by years lived
61+
const yearsLived = inventors.sort((a, b) => (a.passed - a.year) > (b.passed - b.year) ? -1 : 1);
62+
console.table(yearsLived);
5463

5564
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
5665
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris

0 commit comments

Comments
 (0)