|
31 | 31 |
|
32 | 32 | // Array.prototype.filter() |
33 | 33 | // 1. Filter the list of inventors for those who were born in the 1500's |
34 | | - |
35 | 34 | const born = inventors.filter(x => x.year >=1500 && x.year < 1600); |
36 | 35 | console.log(born); |
37 | 36 |
|
38 | 37 | // Array.prototype.map() |
39 | 38 | // 2. Give us an array of the inventors first and last names |
40 | 39 | const finalnamestring = inventors.map(firstandlastname); |
| 40 | + |
41 | 41 | function firstandlastname (x){ |
42 | 42 | const space = ' ' |
43 | 43 | const namestring = x.first + space + x.last; |
44 | 44 | return namestring; |
45 | 45 | //console.log(namestring); |
46 | 46 | } |
| 47 | + |
47 | 48 | console.log(finalnamestring); |
48 | 49 |
|
49 | 50 | // Array.prototype.sort() |
50 | 51 | // 3. Sort the inventors by birthdate, oldest to youngest |
51 | 52 | const sort = inventors.sort(oldesttoyoungest); |
| 53 | + |
52 | 54 | function oldesttoyoungest(a,b){ |
53 | 55 | return a.year-b.year; |
54 | 56 | } |
| 57 | + |
55 | 58 | console.log(sort); |
56 | 59 |
|
57 | 60 | // Array.prototype.reduce() |
58 | 61 | // 4. How many years did all the inventors live all together? |
59 | 62 | const year = inventors.reduce(livetogether, 0); |
| 63 | + |
60 | 64 | function livetogether(totalyears, x){ |
61 | 65 | return totalyears+ (x.passed - x.year); |
62 | 66 | } |
| 67 | + |
63 | 68 | console.log(year); |
64 | 69 |
|
65 | 70 | // 5. Sort the inventors by years lived |
66 | 71 | const sortedyearslived = inventors.sort(yearslived); |
| 72 | + |
67 | 73 | function yearslived(a,b){ |
68 | 74 | return ((b.passed-b.year)-(a.passed-a.year)); |
69 | 75 | } |
| 76 | + |
70 | 77 | console.log(sortedyearslived); |
71 | 78 |
|
72 | 79 | // 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name |
|
0 commit comments