File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 3131
3232 // Array.prototype.filter()
3333 // 1. Filter the list of inventors for those who were born in the 1500's
34+ const fifteen = inventors . filter ( ( inventor ) => {
35+ return inventor . year >= 1500 && inventor . year <= 1600 ;
36+ } ) ;
37+
38+ console . log ( 'Born in 1500:' ) ;
39+ console . log ( fifteen ) ;
3440
3541 // Array.prototype.map()
3642 // 2. Give us an array of the inventors' first and last names
3743
44+ const fullNames = inventors . map ( ( inventor ) => {
45+ return `${ inventor . first } ${ inventor . last } ` ;
46+ } ) ;
47+ console . log ( 'inventors full names:' ) ;
48+ console . log ( fullNames ) ;
49+
3850 // Array.prototype.sort()
3951 // 3. Sort the inventors by birthdate, oldest to youngest
52+ const birthdate = inventors . sort ( ( a , b ) => {
53+ const a_age = a . passed - a . year ;
54+ const b_age = b . passed - b . year ;
55+
56+ return b_age - a_age ;
57+ } )
4058
59+ console . log ( 'Birthday oldest to youngest' ) ;
60+ console . log ( birthdate ) ;
4161 // Array.prototype.reduce()
4262 // 4. How many years did all the inventors live?
4363
You can’t perform that action at this time.
0 commit comments