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