Skip to content

Commit 61ebf2a

Browse files
author
Patrick Santos
committed
complete wesbos#4 challenge
1 parent 2d6fbfc commit 61ebf2a

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,79 @@
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 => {
35+
return inventor.year >= 1500 && inventor.year < 1600;
36+
});
37+
38+
console.table(fifteen)
3439

3540
// Array.prototype.map()
3641
// 2. Give us an array of the inventors' first and last names
42+
const firstLastNames = inventors.map(function(inventor) {
43+
return `${inventor.first} ${inventor.last}`;
44+
});
45+
46+
console.log(firstLastNames);
3747

3848
// Array.prototype.sort()
3949
// 3. Sort the inventors by birthdate, oldest to youngest
50+
const ordered = inventors.sort((a, b) => a.year > b.year ? 1 : -1)
51+
52+
console.table(ordered);
4053

4154
// Array.prototype.reduce()
4255
// 4. How many years did all the inventors live?
56+
const totalYears = inventors.reduce((total, inventor) => {
57+
return total + (inventor.passed - inventor.year);
58+
}, 0);
59+
60+
console.log(totalYears);
4361

4462
// 5. Sort the inventors by years lived
63+
const oldest = inventors.sort(function(a, b) {
64+
const lastGuy = a.passed - a.year;
65+
const nextGuy = b.passed - b.year;
66+
return lastGuy < nextGuy ? 1 : -1;
67+
});
68+
69+
console.log('%c💩', 'font-size: 5em;');
70+
console.table(oldest);
4571

4672
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
4773
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
74+
// const category = document.querySelector('.mw-category');
75+
// const links = [...category.querySelectorAll('a')];
4876

77+
// const de = links
78+
// .map(link => link.textContent)
79+
// .filter(streetName => streetName.includes('de'));
80+
// console.log(de);
4981

5082
// 7. sort Exercise
5183
// Sort the people alphabetically by last name
84+
const alpha = people.sort(function(lastOne, nextOne) {
85+
const [aLast, aFirst] = lastOne.split(', ');
86+
const [bLast, bFirst] = nextOne.split(', ');
87+
88+
return aLast > bLast ? 1 : -1;
89+
});
90+
91+
console.log(alpha);
5292

5393
// 8. Reduce Exercise
5494
// Sum up the instances of each of these
5595
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
5696

97+
const transportation = data.reduce(function(obj, item) {
98+
if (!obj[item]){
99+
obj[item] = 0;
100+
}
101+
obj[item]++;
102+
return obj
103+
}, {});
104+
105+
console.log(transportation);
106+
57107
</script>
58108
</body>
59109
</html>

0 commit comments

Comments
 (0)