Skip to content

Commit a3f9b97

Browse files
author
anirampling
committed
Added solution 4.
1 parent fa3cfb3 commit a3f9b97

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,21 @@
4646

4747
const firstLast = inventors.map( inventors => `${inventors.first} ${inventors.last}` )
4848

49-
console.log(firstLast)
49+
// console.log(firstLast)
5050

5151
// Array.prototype.sort()
5252
// 3. Sort the inventors by birthdate, oldest to youngest
5353
const oldestToYoungest = inventors.sort((a, b) => a.year - b.year)
5454

55-
console.log(oldestToYoungest)
55+
// console.log(oldestToYoungest)
5656

5757
// Array.prototype.reduce()
5858
// 4. How many years did all the inventors live all together?
59+
const yearsLived = inventors.reduce((total, inventor ) => {
60+
return total + inventor.passed - inventor.year
61+
}, 0 )
62+
63+
console.log(yearsLived)
5964

6065
// 5. Sort the inventors by years lived
6166

0 commit comments

Comments
 (0)