Skip to content

Commit 6948291

Browse files
author
Tkum
committed
04 day
1 parent d8eb4dd commit 6948291

1 file changed

Lines changed: 23 additions & 7 deletions

File tree

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

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,45 @@
2727

2828
// Array.prototype.filter()
2929
// 1. Filter the list of inventors for those who were born in the 1500's
30-
30+
console.table(inventors.filter(item => item.year > 1500 && item.year < 1600));
31+
3132
// Array.prototype.map()
3233
// 2. Give us an array of the inventory first and last names
33-
34+
console.log(inventors.map(item => `${item.first} ${item.last}` ));
3435
// Array.prototype.sort()
3536
// 3. Sort the inventors by birthdate, oldest to youngest
37+
console.table(inventors.sort((a, b) => a.year - b.year));
3638

3739
// Array.prototype.reduce()
3840
// 4. How many years did all the inventors live?
39-
41+
console.log(inventors.reduce((total, inventor) => (total += (inventor.passed - inventor.year) ), 0 )) ;
4042
// 5. Sort the inventors by years lived
43+
console.table(inventors.sort((a, b) => {
44+
return (a.passed - a.year) < (b.passed - b.year) ? 1 : -1;
45+
})) ;
4146

4247
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
4348
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
44-
45-
49+
links = [...document.querySelectorAll('.mw-category a')]
50+
links = Array.from(document.querySelectorAll('.mw-category a'));
51+
de = links.map(link => link.textContent)
52+
.filter(item => item.indexOf('de') > -1);
53+
console.log(de);
4654
// 7. sort Exercise
4755
// Sort the people alphabetically by last name
48-
56+
console.log(people.sort((a,b) =>{
57+
const [aLast, aFirst] = a.split(', ');
58+
const [bLast, bFirst] = b.split(', ');
59+
return aLast > bLast ? 1 : -1;
60+
}))
4961
// 8. Reduce Exercise
5062
// Sum up the instances of each of these
5163
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
52-
64+
console.log(data.reduce((obj, item) => {
65+
if (!obj[item]) obj[item] = 0;
66+
obj[item]++;
67+
return obj
68+
},{}));
5369
</script>
5470
</body>
5571
</html>

0 commit comments

Comments
 (0)