File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change 46
46
console . log ( fullName ) ;
47
47
// Array.prototype.sort()
48
48
// 3. Sort the inventors by birthdate, oldest to youngest
49
- const ageSort = inventors . sort ( function sorting ( a , b ) {
49
+ /* const ageSort = inventors.sort(function sorting(a,b){
50
50
if (a.year > b.year){
51
51
return 1
52
52
} else if (a.year == b.year){
55
55
return -1
56
56
};
57
57
58
- } ) ;
58
+ });*/
59
+ const ageSort = inventors . sort ( ( a , b ) => a . year > b . year ? 1 : - 1 ) ;
59
60
console . table ( ageSort ) ;
60
61
// Array.prototype.reduce()
61
62
// 4. How many years did all the inventors live all together?
63
+ const totalYears = inventors . reduce ( ( total , inventor ) => {
64
+ return total + ( inventor . passed - inventor . year ) ;
65
+ } , 0 ) ;
66
+ console . log ( totalYears ) ;
62
67
63
68
// 5. Sort the inventors by years lived
69
+ const yearsLived = inventors . sort ( ( a , b ) => ( a . passed - a . year ) > ( b . passed - b . year ) ? 1 : - 1 ) ;
70
+ console . table ( yearsLived ) ;
64
71
65
72
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
66
73
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
You can’t perform that action at this time.
0 commit comments