Skip to content

Commit b04182c

Browse files
Adds Day 4 Finished Code.
1 parent e51bd7c commit b04182c

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

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

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

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

3738
// Array.prototype.map()
3839
// 2. Give us an array of the inventors' first and last names
40+
const fullNames = inventors.map(inventor => `${inventor.first} ${inventor.last}`);
3941

4042
// Array.prototype.sort()
4143
// 3. Sort the inventors by birthdate, oldest to youngest
44+
const sortedByBirthDate = inventors.sort((a, b) => a.year > b.year ? 1 : -1);
4245

4346
// Array.prototype.reduce()
4447
// 4. How many years did all the inventors live?
48+
const totalYears = inventors.reduce((total, inventor) => total + (inventor.passed - inventor.year), 0);
4549

4650
// 5. Sort the inventors by years lived
51+
const oldest = inventors.sort((a, b) => {
52+
const lastGuy = a.passed - a.year;
53+
const nextGuy = b.passed - b.year;
54+
return lastGuy > nextGuy ? -1 : 1;
55+
});
4756

4857
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
4958
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
50-
59+
// Note: Run this code below on the wikipedia page...
60+
// const category = document.querySelector('.mw-category');
61+
// const links = Array.from(category.querySelectorAll('a'));
62+
// const de = links
63+
// .map(link => link.textContent)
64+
// .filter(streetName => streetName.includes('de'));
5165

5266
// 7. sort Exercise
5367
// Sort the people alphabetically by last name
68+
const alpha = people.sort((lastOne, nextOne) => {
69+
const [aLast, aFirst] = lastOne.split(', ');
70+
const [bLast, bFirst] = nextOne.split(', ');
71+
return aLast > bLast ? 1 : -1;
72+
});
5473

5574
// 8. Reduce Exercise
5675
// Sum up the instances of each of these
5776
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
58-
77+
const transportation = data.reduce((result, vehicle) => {
78+
result[vehicle] = result[vehicle] || 0;
79+
result[vehicle] += 1;
80+
return result;
81+
}, {});
82+
console.log(transportation);
5983
</script>
6084
</body>
6185
</html>

0 commit comments

Comments
 (0)