|
1 | 1 | <!DOCTYPE html> |
2 | 2 | <html lang="en"> |
3 | | -<head> |
4 | | - <meta charset="UTF-8"> |
5 | | - <title>Array Cardio 💪</title> |
6 | | -</head> |
7 | | -<body> |
8 | | - <p><em>Psst: have a look at the JavaScript Console</em> 💁</p> |
9 | | - <script> |
10 | | - // Get your shorts on - this is an array workout! |
11 | | - // ## Array Cardio Day 1 |
| 3 | + <head> |
| 4 | + <meta charset="UTF-8" /> |
| 5 | + <title>Array Cardio 💪</title> |
| 6 | + </head> |
| 7 | + <body> |
| 8 | + <p><em>Psst: have a look at the JavaScript Console</em> 💁</p> |
| 9 | + <script> |
| 10 | + // Get your shorts on - this is an array workout! |
| 11 | + // ## Array Cardio Day 1 |
12 | 12 |
|
13 | | - // Some data we can work with |
| 13 | + // Some data we can work with |
14 | 14 |
|
15 | | - const inventors = [ |
16 | | - { first: 'Albert', last: 'Einstein', year: 1879, passed: 1955 }, |
17 | | - { first: 'Isaac', last: 'Newton', year: 1643, passed: 1727 }, |
18 | | - { first: 'Galileo', last: 'Galilei', year: 1564, passed: 1642 }, |
19 | | - { first: 'Marie', last: 'Curie', year: 1867, passed: 1934 }, |
20 | | - { first: 'Johannes', last: 'Kepler', year: 1571, passed: 1630 }, |
21 | | - { first: 'Nicolaus', last: 'Copernicus', year: 1473, passed: 1543 }, |
22 | | - { first: 'Max', last: 'Planck', year: 1858, passed: 1947 }, |
23 | | - { first: 'Katherine', last: 'Blodgett', year: 1898, passed: 1979 }, |
24 | | - { first: 'Ada', last: 'Lovelace', year: 1815, passed: 1852 }, |
25 | | - { first: 'Sarah E.', last: 'Goode', year: 1855, passed: 1905 }, |
26 | | - { first: 'Lise', last: 'Meitner', year: 1878, passed: 1968 }, |
27 | | - { first: 'Hanna', last: 'Hammarström', year: 1829, passed: 1909 } |
28 | | - ]; |
| 15 | + const inventors = [ |
| 16 | + { first: "Albert", last: "Einstein", year: 1879, passed: 1955 }, |
| 17 | + { first: "Isaac", last: "Newton", year: 1643, passed: 1727 }, |
| 18 | + { first: "Galileo", last: "Galilei", year: 1564, passed: 1642 }, |
| 19 | + { first: "Marie", last: "Curie", year: 1867, passed: 1934 }, |
| 20 | + { first: "Johannes", last: "Kepler", year: 1571, passed: 1630 }, |
| 21 | + { |
| 22 | + first: "Nicolaus", |
| 23 | + last: "Copernicus", |
| 24 | + year: 1473, |
| 25 | + passed: 1543, |
| 26 | + }, |
| 27 | + { first: "Max", last: "Planck", year: 1858, passed: 1947 }, |
| 28 | + { |
| 29 | + first: "Katherine", |
| 30 | + last: "Blodgett", |
| 31 | + year: 1898, |
| 32 | + passed: 1979, |
| 33 | + }, |
| 34 | + { first: "Ada", last: "Lovelace", year: 1815, passed: 1852 }, |
| 35 | + { first: "Sarah E.", last: "Goode", year: 1855, passed: 1905 }, |
| 36 | + { first: "Lise", last: "Meitner", year: 1878, passed: 1968 }, |
| 37 | + { |
| 38 | + first: "Hanna", |
| 39 | + last: "Hammarström", |
| 40 | + year: 1829, |
| 41 | + passed: 1909, |
| 42 | + }, |
| 43 | + ]; |
29 | 44 |
|
30 | | - const people = [ |
31 | | - 'Bernhard, Sandra', 'Bethea, Erin', 'Becker, Carl', 'Bentsen, Lloyd', 'Beckett, Samuel', 'Blake, William', 'Berger, Ric', 'Beddoes, Mick', 'Beethoven, Ludwig', |
32 | | - 'Belloc, Hilaire', 'Begin, Menachem', 'Bellow, Saul', 'Benchley, Robert', 'Blair, Robert', 'Benenson, Peter', 'Benjamin, Walter', 'Berlin, Irving', |
33 | | - 'Benn, Tony', 'Benson, Leana', 'Bent, Silas', 'Berle, Milton', 'Berry, Halle', 'Biko, Steve', 'Beck, Glenn', 'Bergman, Ingmar', 'Black, Elk', 'Berio, Luciano', |
34 | | - 'Berne, Eric', 'Berra, Yogi', 'Berry, Wendell', 'Bevan, Aneurin', 'Ben-Gurion, David', 'Bevel, Ken', 'Biden, Joseph', 'Bennington, Chester', 'Bierce, Ambrose', |
35 | | - 'Billings, Josh', 'Birrell, Augustine', 'Blair, Tony', 'Beecher, Henry', 'Biondo, Frank' |
36 | | - ]; |
37 | | - |
38 | | - // Array.prototype.filter() |
39 | | - // 1. Filter the list of inventors for those who were born in the 1500's |
| 45 | + const people = [ |
| 46 | + "Bernhard, Sandra", |
| 47 | + "Bethea, Erin", |
| 48 | + "Becker, Carl", |
| 49 | + "Bentsen, Lloyd", |
| 50 | + "Beckett, Samuel", |
| 51 | + "Blake, William", |
| 52 | + "Berger, Ric", |
| 53 | + "Beddoes, Mick", |
| 54 | + "Beethoven, Ludwig", |
| 55 | + "Belloc, Hilaire", |
| 56 | + "Begin, Menachem", |
| 57 | + "Bellow, Saul", |
| 58 | + "Benchley, Robert", |
| 59 | + "Blair, Robert", |
| 60 | + "Benenson, Peter", |
| 61 | + "Benjamin, Walter", |
| 62 | + "Berlin, Irving", |
| 63 | + "Benn, Tony", |
| 64 | + "Benson, Leana", |
| 65 | + "Bent, Silas", |
| 66 | + "Berle, Milton", |
| 67 | + "Berry, Halle", |
| 68 | + "Biko, Steve", |
| 69 | + "Beck, Glenn", |
| 70 | + "Bergman, Ingmar", |
| 71 | + "Black, Elk", |
| 72 | + "Berio, Luciano", |
| 73 | + "Berne, Eric", |
| 74 | + "Berra, Yogi", |
| 75 | + "Berry, Wendell", |
| 76 | + "Bevan, Aneurin", |
| 77 | + "Ben-Gurion, David", |
| 78 | + "Bevel, Ken", |
| 79 | + "Biden, Joseph", |
| 80 | + "Bennington, Chester", |
| 81 | + "Bierce, Ambrose", |
| 82 | + "Billings, Josh", |
| 83 | + "Birrell, Augustine", |
| 84 | + "Blair, Tony", |
| 85 | + "Beecher, Henry", |
| 86 | + "Biondo, Frank", |
| 87 | + ]; |
40 | 88 |
|
41 | | - // Array.prototype.map() |
42 | | - // 2. Give us an array of the inventors first and last names |
| 89 | + // Array.prototype.filter() |
| 90 | + // 1. Filter the list of inventors for those who were born in the 1500's |
| 91 | + const inventorsOf1500s = inventors.filter((inventor) => { |
| 92 | + return inventor.year > 1499 && inventor.year < 1600 |
| 93 | + ? true |
| 94 | + : false; |
| 95 | + }); |
| 96 | + const inventorsOf1800s = inventors.filter((inventor) => { |
| 97 | + return inventor.year > 1799 && inventor.year < 1900 |
| 98 | + ? true |
| 99 | + : false; |
| 100 | + }); |
| 101 | + const inventorsWithAName = inventors.filter((inventor) => { |
| 102 | + return inventor.first.startsWith("A") ? true : false; |
| 103 | + }); |
| 104 | + // console.table(inventorsOf1500s); |
| 105 | + // console.table(inventorsOf1800s); |
| 106 | + // console.table(inventorsWithAName); |
43 | 107 |
|
44 | | - // Array.prototype.sort() |
45 | | - // 3. Sort the inventors by birthdate, oldest to youngest |
| 108 | + // Array.prototype.map() |
| 109 | + // 2. Give us an array of the inventors first and last names |
46 | 110 |
|
47 | | - // Array.prototype.reduce() |
48 | | - // 4. How many years did all the inventors live all together? |
| 111 | + // Array.prototype.sort() |
| 112 | + // 3. Sort the inventors by birthdate, oldest to youngest |
49 | 113 |
|
50 | | - // 5. Sort the inventors by years lived |
| 114 | + // Array.prototype.reduce() |
| 115 | + // 4. How many years did all the inventors live all together? |
51 | 116 |
|
52 | | - // 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name |
53 | | - // https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris |
| 117 | + // 5. Sort the inventors by years lived |
54 | 118 |
|
| 119 | + // 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name |
| 120 | + // https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris |
55 | 121 |
|
56 | | - // 7. sort Exercise |
57 | | - // Sort the people alphabetically by last name |
| 122 | + // 7. sort Exercise |
| 123 | + // Sort the people alphabetically by last name |
58 | 124 |
|
59 | | - // 8. Reduce Exercise |
60 | | - // Sum up the instances of each of these |
61 | | - const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ]; |
62 | | - |
63 | | - </script> |
64 | | -</body> |
| 125 | + // 8. Reduce Exercise |
| 126 | + // Sum up the instances of each of these |
| 127 | + const data = [ |
| 128 | + "car", |
| 129 | + "car", |
| 130 | + "truck", |
| 131 | + "truck", |
| 132 | + "bike", |
| 133 | + "walk", |
| 134 | + "car", |
| 135 | + "van", |
| 136 | + "bike", |
| 137 | + "walk", |
| 138 | + "car", |
| 139 | + "van", |
| 140 | + "car", |
| 141 | + "truck", |
| 142 | + ]; |
| 143 | + </script> |
| 144 | + </body> |
65 | 145 | </html> |
0 commit comments