@@ -62,42 +62,39 @@ const people = [
62
62
63
63
// Array.prototype.filter()
64
64
// 1. Filter the list of inventors for those who were born in the 1500's
65
- // const a = inventors.filter(
66
- // (inventor) => inventor.year < 1600 && 1500 <= inventor.year
67
- // );
68
- // console.table(a);
65
+ const a = inventors . filter (
66
+ ( inventor ) => inventor . year < 1600 && 1500 <= inventor . year
67
+ ) ;
68
+ console . table ( a ) ;
69
69
70
70
// Array.prototype.map()
71
71
// 2. Give us an array of the inventors first and last names
72
- // const b = inventors.map((inventor) =>
73
- // console.log(`${inventor.first} ${inventor.last}`)
74
- // );
72
+ const b = inventors . map ( ( inventor ) => `${ inventor . first } ${ inventor . last } ` ) ;
73
+ console . log ( b ) ;
75
74
76
75
// Array.prototype.sort()
77
76
// 3. Sort the inventors by birthdate, oldest to youngest
78
- // const c = inventors.sort((i, l) => i.year - l.year);
79
- // console.table(c);
77
+ const c = inventors . sort ( ( i , l ) => i . year - l . year ) ;
78
+ console . table ( c ) ;
80
79
81
80
// Array.prototype.reduce()
82
81
// 4. How many years did all the inventors live all together?
83
- // let d = inventors.reduce(function (acc, inventor) {
84
- // return acc + (inventor.passed - inventor.year);
85
- // }, 0);
86
- // console.log(d);
82
+ const d = inventors . reduce (
83
+ ( acc , inventor ) => acc + ( inventor . passed - inventor . year ) ,
84
+ 0
85
+ ) ;
86
+ console . log ( d ) ;
87
87
88
88
// 5. Sort the inventors by years lived
89
- // let f = inventors.sort((a, b) => a .passed - b.year);
90
- // console.log (f);
89
+ let f = inventors . sort ( ( a , b ) => b . passed - b . year - ( a . passed - a . year ) ) ;
90
+ console . table ( f ) ;
91
91
92
92
// 6. Create a list of Boulevards in Paris that contain 'de' anywhere in the name
93
93
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
94
94
95
95
// 7. Sort exercise
96
96
// Sort the people alphabetically by last name
97
- // for (let i = 0; i < people.length; i++) {
98
- // let lastName = people[i].split(" ")[1];
99
- // console.log();
100
- // }
97
+ console . log ( people . sort ( ) ) ;
101
98
102
99
// 8. Reduce exercise
103
100
// Sum up the instances of each of these
0 commit comments