File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 4545
4646 // Array.prototype.map()
4747 // 2. Give us an array of the inventors' first and last names
48+
49+ //this is the function to run in the map method
50+ inventors . map (
51+ function joinNames ( currentItem , indexOfItem ) {
52+ let fullName = [ currentItem . first , currentItem . last ] . join ( " " ) ;
53+ console . log ( fullName )
54+ } ) ;
55+
4856
4957 // Array.prototype.sort()
5058 // 3. Sort the inventors by birthdate, oldest to youngest
59+ // compare function will be needed
60+ let sortbyYears = inventors . sort ( function ( firstPerson , secondPerson ) {
61+ if ( firstPerson . year > secondPerson . year ) { console . log ( firstPerson , secondPerson ) ; return 1 } else { return - 1 }
62+
63+ } )
5164
65+ console . log ( sortbyYears ) ;
5266 // Array.prototype.reduce()
5367 // 4. How many years did all the inventors live?
5468
You can’t perform that action at this time.
0 commit comments