|
23 | 23 |
|
24 | 24 | const flavours = ['Chocolate Chip', 'Kulfi', 'Caramel Praline', 'Chocolate', 'Burnt Caramel', 'Pistachio', 'Rose', 'Sweet Coconut', 'Lemon Cookie', 'Toffeeness', 'Toasted Almond', 'Black Raspberry Crunch', 'Chocolate Brownies', 'Pistachio Almond', 'Strawberry', 'Lavender Honey', 'Lychee', 'Peach', 'Black Walnut', 'Birthday Cake', 'Mexican Chocolate', 'Mocha Almond Fudge', 'Raspberry']; |
25 | 25 |
|
26 | | - const people = ['Beck, Glenn', 'Becker, Carl', 'Beckett, Samuel', 'Beddoes, Mick', 'Beecher, Henry', 'Beethoven, Ludwig', 'Begin, Menachem', 'Belloc, Hilaire', 'Bellow, Saul', 'Benchley, Robert', 'Benenson, Peter', 'Ben-Gurion, David', 'Benjamin, Walter', 'Benn, Tony', 'Bennington, Chester', 'Benson, Leana', 'Bent, Silas', 'Bentsen, Lloyd', 'Berger, Ric', 'Bergman, Ingmar', 'Berio, Luciano', 'Berle, Milton', 'Berlin, Irving', 'Berne, Eric', 'Bernhard, Sandra', 'Berra, Yogi', 'Berry, Halle', 'Berry, Wendell', 'Bethea, Erin', 'Bevan, Aneurin', 'Bevel, Ken', 'Biden, Joseph', 'Bierce, Ambrose', 'Biko, Steve', 'Billings, Josh', 'Biondo, Frank', 'Birrell, Augustine', 'Black Elk', 'Blair, Robert', 'Blair, Tony', 'Blake, William']; |
| 26 | + const people = ['Becker, Carl', 'Beckett, Samuel', 'Beddoes, Mick', 'Beecher, Henry', 'Beethoven, Ludwig', 'Begin, Menachem', 'Berger, Ric', 'Belloc, Hilaire', 'Bellow, Saul', 'Benchley, Robert', 'Benenson, Peter', 'Ben-Gurion, David', 'Benjamin, Walter', 'Benn, Tony', 'Bennington, Chester', 'Blake, William', 'Benson, Leana', 'Bent, Silas', 'Bentsen, Lloyd', 'Bergman, Ingmar', 'Berio, Luciano', 'Berle, Milton', 'Berlin, Irving', 'Berne, Eric', 'Bernhard, Sandra', 'Berra, Yogi', 'Berry, Halle', 'Berry, Wendell', 'Bethea, Erin', 'Bevan, Aneurin', 'Bevel, Ken', 'Beck, Glenn', 'Biden, Joseph', 'Bierce, Ambrose', 'Biko, Steve', 'Billings, Josh', 'Biondo, Frank', 'Birrell, Augustine', 'Black Elk', 'Blair, Robert', 'Blair, Tony']; |
27 | 27 |
|
28 | 28 | // Array.prototype.filter() |
29 | 29 | // 1. Filter the list of inventors for those who were born in the 1500's |
|
48 | 48 | return nextInventorAge - lastInventorAge; |
49 | 49 | } |
50 | 50 | ); |
51 | | - console.table(byOldest); |
| 51 | + console.table('by oldest: ', byOldest); |
| 52 | + |
52 | 53 | // 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name |
53 | 54 | // https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris |
| 55 | + const category = document.querySelector('.mw-category'); |
| 56 | + // change this into an array! |
| 57 | + const links = Array.from(category.querySelectorAll('a')); |
| 58 | + |
| 59 | + const de = links |
| 60 | + .map(link => link.textContent) |
| 61 | + .filter(streetName => streetName.includes('de')); |
54 | 62 |
|
55 | 63 |
|
56 | 64 | // 7. sort Exercise |
57 | 65 | // Sort the people alphabetically by last name |
| 66 | + const alpha = people.sort(function(lastOne, nextOne) { |
| 67 | + const [aLast, aFirst] = lastOne.split(', '); |
| 68 | + const [bLast, bFirst] = nextOne.split(', '); |
| 69 | + |
| 70 | + console.log(last, first); |
| 71 | + }); |
58 | 72 |
|
59 | 73 | // 8. Reduce Exercise |
60 | 74 | // Sum up the instances of each of these |
61 | 75 | const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ]; |
62 | 76 |
|
| 77 | + const transportation = data.reduce(function(obj, item) { |
| 78 | + console.log('obj: ', obj); |
| 79 | + console.log('item: ', item); |
| 80 | + if(!obj[item]) { |
| 81 | + obj[item] = 0; |
| 82 | + } |
| 83 | + obj[item]++; |
| 84 | + return obj; |
| 85 | + }, {}) |
| 86 | + |
| 87 | + console.log(transportation); |
| 88 | + |
63 | 89 | </script> |
64 | 90 | </body> |
65 | 91 | </html> |
0 commit comments