Skip to content

Commit e0b773d

Browse files
committed
finishing 4
1 parent fc44b64 commit e0b773d

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,68 @@
3131

3232
// Array.prototype.filter()
3333
// 1. Filter the list of inventors for those who were born in the 1500's
34+
const fifteen = inventors.filter(inventor => inventor.year >= 1500 && inventor.year < 1600);
35+
console.table(fifteen);
3436

3537
// Array.prototype.map()
3638
// 2. Give us an array of the inventors' first and last names
39+
const fullNames = inventors.map(inventor => `${inventor.first} ${inventor.last}`);
40+
console.log(fullNames);
3741

3842
// Array.prototype.sort()
3943
// 3. Sort the inventors by birthdate, oldest to youngest
44+
const ordered = inventors.sort((a, b) => (a.year > b.year) ? 1 : -1);
45+
46+
console.table(ordered);
4047

4148
// Array.prototype.reduce()
4249
// 4. How many years did all the inventors live?
50+
const totalYears = inventors.reduce((total, inventor) => {
51+
return total + (inventor.passed - inventor.year);
52+
}, 0);
53+
54+
console.log(totalYears);
4355

4456
// 5. Sort the inventors by years lived
57+
const oldest = inventors.sort(function (a, b) {
58+
const lastGuy = a.passed - a.year;
59+
const nextGuy = b.passed - b.year;
60+
return lastGuy > nextGuy ? -1 : 1;
61+
});
62+
console.table(oldest);
4563

4664
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
4765
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
66+
// const category = document.querySelector('.mw-category');
67+
// const links = Array.from(category.querySelectorAll('a'));
68+
// const de = links
69+
// .map(link => link.textContent)
70+
// .filter(streetName => streetName.includes('de'));
4871

4972

5073
// 7. sort Exercise
5174
// Sort the people alphabetically by last name
75+
const alpha = people.sort((lastOne, nextOne) => {
76+
const [aLast, aFirst] = lastOne.split(', ');
77+
const [bLast, bFirst] = nextOne.split(', ');
78+
return aLast > bLast ? -1 : 1;
79+
});
80+
console.log(alpha);
5281

5382
// 8. Reduce Exercise
5483
// Sum up the instances of each of these
5584
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
5685

86+
const transportation = data.reduce(function (obj, item) {
87+
if (!obj[item]) {
88+
obj[item] = 0;
89+
}
90+
obj[item]++;
91+
return obj;
92+
}, {});
93+
94+
console.log(transportation);
95+
5796
</script>
5897
</body>
5998
</html>

0 commit comments

Comments
 (0)