Skip to content

Commit f3763bf

Browse files
committed
Start with Arrays
1 parent 49d4a40 commit f3763bf

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,24 @@
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+
37+
//console.table (fifteen);
38+
3539
// Array.prototype.map()
3640
// 2. Give us an array of the inventors' first and last names
37-
41+
const fullNames = inventors.map(inventor => `${inventor.first} ${inventor.last}`);
42+
//console.log(fullNames);
3843
// Array.prototype.sort()
3944
// 3. Sort the inventors by birthdate, oldest to youngest
40-
45+
46+
const ordered = inventors.sort((a,b) => a.year > b.year ? 1:-1);
47+
//console.table(ordered);
4148
// Array.prototype.reduce()
4249
// 4. How many years did all the inventors live?
50+
const lived = inventors.reduce((total, inventor)=> {return total + (inventor.passed - inventor.year);
51+
}, 0);
52+
console.log (lived);
4353

4454
// 5. Sort the inventors by years lived
4555

0 commit comments

Comments
 (0)