Skip to content

Commit 3c9333a

Browse files
committed
Adding Day 4
1 parent 38a754c commit 3c9333a

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

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

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

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

3134
// Array.prototype.map()
3235
// 2. Give us an array of the inventory first and last names
36+
var names = inventors.map((inventor) =>
37+
[inventor.first, inventor.last]
38+
);
3339

3440
// Array.prototype.sort()
3541
// 3. Sort the inventors by birthdate, oldest to youngest
42+
var sortedInventors = inventors.sort((cur, prev) =>
43+
cur.year > prev.year
44+
);
3645

3746
// Array.prototype.reduce()
3847
// 4. How many years did all the inventors live?
48+
var sumYears = inventors.reduce((sum, inventor) => {
49+
return (inventor.passed - inventor.year) + sum;
50+
}, 0);
3951

4052
// 5. Sort the inventors by years lived
53+
var oldestInventors = inventors.sort((cur, prev) =>
54+
(cur.passed - cur.year) < (prev.passed - prev.year)
55+
);
4156

4257
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
4358
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
44-
59+
/*
60+
var category = document.querySelector('.mw-category');
61+
var links = Array.from(category.querySelectorAll('a'));
62+
var deLinks = links.filter(link => link.innerHTML.indexOf('de') > -1);
63+
*/
4564

4665
// 7. sort Exercise
4766
// Sort the people alphabetically by last name
67+
var sortedNames = people.sort((cur, prev) =>
68+
cur.split(',')[0] < prev.split(',')[0] ? -1 : 1
69+
);
4870

4971
// 8. Reduce Exercise
5072
// Sum up the instances of each of these
5173
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
74+
var reducedData = data.reduce((arr, piece) => {
75+
if (arr.indexOf(piece) < 0) {
76+
arr.push(piece)
77+
}
78+
return arr;
79+
}, []);
5280

5381
</script>
5482
</body>

0 commit comments

Comments
 (0)