Skip to content

Commit 3679987

Browse files
committed
one more
1 parent 79f6834 commit 3679987

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

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

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,64 @@
3131

3232
// Array.prototype.filter()
3333
// 1. Filter the list of inventors for those who were born in the 1500's
34-
34+
const fifteen = inventors.filter(inventor => inventor.year >= 1500 && inventor.year < 1600);
35+
console.table(fifteen);
3536
// Array.prototype.map()
3637
// 2. Give us an array of the inventors' first and last names
38+
const names = inventors.map(inventor => inventor.first + ' ' + inventor.last);
39+
console.log(names);
3740

3841
// Array.prototype.sort()
3942
// 3. Sort the inventors by birthdate, oldest to youngest
40-
43+
const bday = inventors.sort((a,b) => a.year > b.year ? 1 : -1);
44+
console.table(bday);
4145
// Array.prototype.reduce()
4246
// 4. How many years did all the inventors live?
47+
const totalYears = inventors.reduce((total, inventor) => {
48+
return total + (inventor.passed - inventor.year);
49+
}, 0);
50+
console.log(totalYears);
51+
4352

4453
// 5. Sort the inventors by years lived
54+
const oldest = inventors.sort((a,b) => {
55+
const last = a.passed - a.year;
56+
const next = a.passed - a.year;
57+
last > next ? 1 : -1
58+
})
59+
console.table(oldest);
4560

4661
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
4762
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
48-
63+
// const category = document.querySelector('.mw-category');
64+
// const links = Array.from(category.querySelectorAll('a'));
65+
// const de = links
66+
// .map(link => link.textContent)
67+
// .filter(streetName => streetName.includes('de'));
68+
// console.log(de);
4969

5070
// 7. sort Exercise
5171
// Sort the people alphabetically by last name
72+
const alpha = people.sort((lastOne, nextOne) => {
73+
const [aLast, aFirst] = lastOne.split(', ');
74+
const [bLast, bFirst] = nextOne.split(', ');
75+
return aLast > bLast ? 1 : -1
76+
});
77+
console.log(alpha);
5278

5379
// 8. Reduce Exercise
5480
// Sum up the instances of each of these
5581
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
5682

83+
const transport = data.reduce((obj, item) => {
84+
if(!obj[item]) {
85+
obj[item] = 0;
86+
}
87+
obj[item]++
88+
return obj;
89+
}, {});
90+
console.log(transport);
91+
5792
</script>
5893
</body>
5994
</html>

0 commit comments

Comments
 (0)