File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change 36
36
37
37
// Array.prototype.filter()
38
38
// 1. Filter the list of inventors for those who were born in the 1500's
39
- // const fifteen = inventors.filter(inventor => inventor.year >= 1500 && inventor.year < 1600);
40
- // console.table(fifteen);
39
+ const fifteen = inventors . filter ( inventor => inventor . year >= 1500 && inventor . year < 1600 ) ;
40
+ console . table ( fifteen ) ;
41
41
42
42
// Array.prototype.map()
43
43
// 2. Give us an array of the inventors' first and last names
46
46
47
47
// Array.prototype.sort()
48
48
// 3. Sort the inventors by birthdate, oldest to youngest
49
+ const sorted = inventors . sort ( ( a , b ) => a . year > b . year ? 1 : - 1 ) ;
50
+ console . table ( sorted ) ;
51
+
49
52
50
53
// Array.prototype.reduce()
51
54
// 4. How many years did all the inventors live?
55
+ const totalYears = inventors . reduce ( ( total , inventor ) => {
56
+ return total + ( inventor . passed - inventor . year ) ;
57
+ } , 0 ) ;
58
+ console . log ( totalYears ) ;
52
59
53
60
// 5. Sort the inventors by years lived
61
+ const yearsLived = inventors . sort ( ( a , b ) => ( a . passed - a . year ) > ( b . passed - b . year ) ? - 1 : 1 ) ;
62
+ console . table ( yearsLived ) ;
54
63
55
64
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
56
65
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
You can’t perform that action at this time.
0 commit comments