Skip to content

Commit 7608b21

Browse files
committed
solved the first 4 problems. 4 still to do.
1 parent a23f7ec commit 7608b21

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,26 @@
3838

3939
// Array.prototype.filter()
4040
// 1. Filter the list of inventors for those who were born in the 1500's
41+
const inventorsBornIn1500s = inventors.filter(inventor => inventor.year >= 1500 && inventor.year < 1600);
42+
console.table(inventorsBornIn1500s);
43+
4144

4245
// Array.prototype.map()
4346
// 2. Give us an array of the inventors first and last names
47+
const inventorFullNames = inventors.map((inventor) => inventor.first + " " + inventor.last);
48+
console.table(inventorFullNames);
4449

4550
// Array.prototype.sort()
4651
// 3. Sort the inventors by birthdate, oldest to youngest
52+
const byBirthDate = inventors.sort((a, b) => a.year - b.year);
53+
console.table(byBirthDate);
4754

4855
// Array.prototype.reduce()
4956
// 4. How many years did all the inventors live all together?
57+
const totalYears = inventors.reduce((total, inventor) => {
58+
return total + (inventor.passed - inventor.year);
59+
}, 0);
60+
console.table(totalYears);
5061

5162
// 5. Sort the inventors by years lived
5263

0 commit comments

Comments
 (0)