Skip to content
This repository was archived by the owner on Feb 13, 2022. It is now read-only.

Commit f347615

Browse files
committed
solution wesbos#4
1 parent d9c0ac2 commit f347615

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,61 @@
2727

2828
// Array.prototype.filter()
2929
// 1. Filter the list of inventors for those who were born in the 1500's
30+
const born1500 = inventors.filter(inventor =>
31+
inventor.year >= 1500 && inventor.year < 1600
32+
);
33+
console.table(born1500);
3034

3135
// Array.prototype.map()
3236
// 2. Give us an array of the inventory first and last names
37+
const names = inventors.map(inventor =>
38+
`${inventor.first} ${inventor.last}`
39+
);
40+
console.log(names);
3341

3442
// Array.prototype.sort()
3543
// 3. Sort the inventors by birthdate, oldest to youngest
44+
const sortByBirthday = inventors.sort((a, b) => a.year - b.year);
45+
console.table(sortByBirthday);
3646

3747
// Array.prototype.reduce()
3848
// 4. How many years did all the inventors live?
49+
const inventorsLive = inventors.reduce((count, inventor) =>
50+
count + inventor.passed - inventor.year
51+
, 0);
52+
console.log(inventorsLive);
3953

4054
// 5. Sort the inventors by years lived
55+
const sortByYearsLived = inventors.sort((a, b) =>
56+
(b.passed - b.year) - (a.passed - a.year)
57+
);
58+
console.table(sortByYearsLived);
4159

4260
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
4361
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
44-
62+
const category = document.querySelector('.mw-category');
63+
// const links = [...category.querySelectorAll('a')];
64+
const links = Array.from(category.querySelectorAll('a'));
65+
const de = links
66+
.map(link => link.textContent)
67+
.filter(name => name.includes('de'));
4568

4669
// 7. sort Exercise
4770
// Sort the people alphabetically by last name
71+
const sortedByLastName = people.sort((a, b) =>
72+
a.split(', ')[0] > b.split(', ')[0] ? 1 : -1
73+
);
74+
console.log(sortedByLastName);
4875

4976
// 8. Reduce Exercise
5077
// Sum up the instances of each of these
5178
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
79+
const sum = data.reduce((obj, t) => {
80+
obj[t] ? obj[t]++ : obj[t] = 1;
81+
82+
return obj;
83+
}, {});
84+
console.log(sum);
5285

5386
</script>
5487
</body>

0 commit comments

Comments
 (0)