Skip to content

Commit 7d98f5c

Browse files
committed
JS30 day wesbos#4 done
1 parent 81cd7cf commit 7d98f5c

1 file changed

Lines changed: 44 additions & 3 deletions

File tree

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

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,69 @@
3131

3232
// Array.prototype.filter()
3333
// 1. Filter the list of inventors for those who were born in the 1500's
34-
34+
const yearBornFilter = inventors.filter(el => el.year >= 1500 && el.year < 1600);
35+
36+
// console.table(yearBornFilter);
37+
3538
// Array.prototype.map()
3639
// 2. Give us an array of the inventors' first and last names
40+
const names = inventors.map((el) => {
41+
return [el.first, el.last];
42+
});
43+
// console.table(names);
3744

3845
// Array.prototype.sort()
3946
// 3. Sort the inventors by birthdate, oldest to youngest
47+
const byAge = inventors.sort((a, b) => {
48+
return a.year > b.year ? 1 : -1;
49+
})
50+
// console.table(byAge);
4051

4152
// Array.prototype.reduce()
4253
// 4. How many years did all the inventors live?
43-
54+
const totalYears = inventors.reduce((total, inventor) => {
55+
return total + (inventor.passed - inventor.year);
56+
}, 0);
57+
// console.log(totalYears);
58+
4459
// 5. Sort the inventors by years lived
45-
60+
const yearsLived = inventors.sort((a, b) => {
61+
return (a.passed - a.year) > (b.passed - b.year) ? -1 : 1;
62+
})
63+
// console.table(yearsLived);
64+
4665
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
4766
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
67+
// const category = document.querySelector('.mw-category');
68+
// const blvds = [...category.querySelectorAll('a')];
69+
// const de = blvds
70+
// .map(blvd => blvd.textContent)
71+
// .filter(item => item.includes('de'));
72+
4873

4974

5075
// 7. sort Exercise
5176
// Sort the people alphabetically by last name
77+
let sorts = people.sort((a, b) => {
78+
return a.split(', ')[0] > b.split(', ')[0] ? 1 : -1;
79+
})
80+
// console.log(sorts);
81+
82+
5283

5384
// 8. Reduce Exercise
5485
// Sum up the instances of each of these
5586
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
87+
const totals = data.reduce((obj, item) => {
88+
if (!obj[item]) obj[item] = 0;
89+
obj[item]++;
90+
91+
return obj;
92+
93+
94+
}, {})
95+
console.log(totals);
96+
5697

5798
</script>
5899
</body>

0 commit comments

Comments
 (0)