Skip to content

Commit 27df563

Browse files
author
Alexander Besse
committed
wesbos#4 Completed.
1 parent aad46e6 commit 27df563

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,49 @@
3131

3232
// Array.prototype.filter()
3333
// 1. Filter the list of inventors for those who were born in the 1500's
34+
console.log(`Inventors that were born in the 1500s: `, inventors.filter(inventor => inventor.year >= 1500 && inventor.year <= 1599));
3435

3536
// Array.prototype.map()
3637
// 2. Give us an array of the inventors first and last names
37-
38+
console.log(`All the first and last names of inventors: `, inventors.map(inventor => ({first: inventor.first, last: inventor.last})));
39+
3840
// Array.prototype.sort()
3941
// 3. Sort the inventors by birthdate, oldest to youngest
42+
console.log(`All the inventors sorted by birthday (oldest to youngest): `, inventors.sort((a, b) => a.year < b.year ? -1 : 1));
4043

4144
// Array.prototype.reduce()
4245
// 4. How many years did all the inventors live all together?
46+
console.log(`The amount of years the inventors lived, accumulated: `, inventors.reduce((counter, item) => counter + (item.passed - item.year), 0));
47+
4348

4449
// 5. Sort the inventors by years lived
50+
console.log(`The inventors sorted by how many years they lived: `, inventors.sort((a, b) => (a.passed - a.year) < (b.passed - b.year) ? 1 : -1));
51+
4552

4653
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
4754
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
48-
55+
/*
56+
const mw = document.querySelector('.mw-category');
57+
const titles = mw.from(document.querySelector('a')).map(item => item.textContent);
58+
const de = titles.filter(title => title.includes('de'));
59+
*/
4960

5061
// 7. sort Exercise
5162
// Sort the people alphabetically by last name
52-
63+
console.log(`The people's names sorted alphabetically: `, inventors.sort((a, b) => a.last.split("")[0] > b.last.split("")[0] ? 1 : -1));
64+
5365
// 8. Reduce Exercise
5466
// Sum up the instances of each of these
5567
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
56-
68+
console.log(`Sum of instances of cars: `, data.reduce((counter, car) => {
69+
if(!counter[car]) {
70+
counter[car] = 1;
71+
}else {
72+
counter[car] += 1;
73+
}
74+
return counter;
75+
}, {}));
76+
5777
</script>
5878
</body>
5979
</html>

0 commit comments

Comments
 (0)