File tree 1 file changed +13
-1
lines changed
1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change 103
103
104
104
// Array.prototype.reduce()
105
105
// 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 ) ;
107
107
108
108
let totalYearsLived = yearsLived . reduce ( ( total , currentValue ) => total + currentValue ) ;
109
109
console . log ( totalYearsLived ) ;
110
110
111
111
// 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 ) ;
112
124
113
125
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
114
126
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
You can’t perform that action at this time.
0 commit comments