Skip to content

Commit 2eb7ee3

Browse files
author
Brian Carrigan
committed
Day 4 - Complete.
1 parent b6d0438 commit 2eb7ee3

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

04 - Array Cardio Day 1/index-START.html

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,50 @@
3333

3434
// Array.prototype.filter()
3535
// 1. Filter the list of inventors for those who were born in the 1500's
36+
const fifteens = inventors.filter(inventor => inventor.year >= 1500 && inventor.year < 1600);
37+
console.log(fifteens);
3638

3739
// Array.prototype.map()
3840
// 2. Give us an array of the inventors' first and last names
41+
const names = inventors.map(inventor => `${inventor.first} ${inventor.last}`);
42+
console.log(names);
3943

4044
// Array.prototype.sort()
4145
// 3. Sort the inventors by birthdate, oldest to youngest
46+
const sorted = inventors.sort((a, b) => a.year - b.year);
47+
console.table(sorted);
4248

4349
// Array.prototype.reduce()
4450
// 4. How many years did all the inventors live?
51+
const total = inventors.reduce((acc, current) => acc + (current.passed - current.year), 0);
52+
console.log(total);
4553

4654
// 5. Sort the inventors by years lived
55+
const sortedTotal = inventors.sort((a, b) => (a.passed - a.year) - (b.passed - b.year));
56+
console.table(sortedTotal);
4757

4858
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
4959
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
50-
60+
// const paris = ["Boulevards of Paris", "City walls of Paris", "Thiers wall", "Wall of Charles V", "Wall of Philip II Augustus", "City gates of Paris", "Haussmann's renovation of Paris", "Boulevards of the Marshals", "Boulevard Auguste-Blanqui", "Boulevard Barbès", "Boulevard Beaumarchais", "Boulevard de l'Amiral-Bruix", "Boulevard de Strasbourg", "Boulevard des Capucines", "Boulevard de la Chapelle", "Boulevard de Clichy", "Boulevard du Crime", "Boulevard Haussmann", "Boulevard de l'Hopital", "Boulevard des Italiens", "Boulevard de la Madeleine", "Boulevard de Magenta", "Boulevard Montmartre", "Boulevard du Montparnasse", "Boulevard Raspail", "Boulevard Richard-Lenoir", "Boulevard de Rochechouart", "Boulevard Saint-Germain", "Boulevard Saint-Michel", "Boulevard de Sébastopol", "Boulevard du Temple", "Boulevard Voltaire", "Boulevard de la Zone"];
61+
// console.log(paris.filter(q => q.includes("de")));
5162

5263
// 7. sort Exercise
5364
// Sort the people alphabetically by last name
65+
const pplSorted = people
66+
.map(person => person.split(', '))
67+
.sort(([aLast, _a], [bLast, _b]) => aLast > bLast ? 1 : -1)
68+
.map(([last, first]) => `${first} ${last}`);
69+
70+
console.log(pplSorted);
5471

5572
// 8. Reduce Exercise
5673
// Sum up the instances of each of these
5774
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
58-
75+
const counts = data.reduce((output, current) => {
76+
output[current] = (output[current] || 0) + 1;
77+
return output;
78+
}, {});
79+
console.log(counts);
5980
</script>
6081
</body>
6182
</html>

0 commit comments

Comments
 (0)