Skip to content

Commit 47e47bc

Browse files
committed
complete exercise wesbos#5 from 04 - array cardio
1 parent d9efc40 commit 47e47bc

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

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

+13-1
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,24 @@
103103

104104
// Array.prototype.reduce()
105105
// 4. How many years did all the inventors live all together?
106-
const yearsLived = inventors.map((inventor) => inventor.passed - inventor.year);
106+
let yearsLived = inventors.map((inventor) => inventor.passed - inventor.year);
107107

108108
let totalYearsLived = yearsLived.reduce((total, currentValue) => total + currentValue);
109109
console.log(totalYearsLived);
110110

111111
// 5. Sort the inventors by years lived
112+
function addYears (inventor) {
113+
let yearsLived = inventor.passed - inventor.year
114+
inventor.lived = yearsLived;
115+
return inventor;
116+
}
117+
118+
const inventorsCopy = JSON.parse(JSON.stringify(inventors));
119+
let inventorsWirhYearsLived = inventorsCopy
120+
.map(addYears)
121+
.sort((inventor1, inventor2) => inventor1.lived - inventor2.lived);
122+
123+
console.log(inventorsWirhYearsLived);
112124

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

0 commit comments

Comments
 (0)