Skip to content

Commit 41ea33d

Browse files
committed
1 parent 5bb82ea commit 41ea33d

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,52 @@
3232
// Array.prototype.filter()
3333
// 1. Filter the list of inventors for those who were born in the 1500's
3434

35+
const fifteens = inventors.filter(i => i.year > 1500 && i.year < 1600);
36+
//console.table(fifteens);
37+
38+
3539
// Array.prototype.map()
3640
// 2. Give us an array of the inventors' first and last names
3741

42+
const list = inventors.map(i => `${i.first} ${i.last}`);
43+
//console.log(list);
44+
45+
3846
// Array.prototype.sort()
3947
// 3. Sort the inventors by birthdate, oldest to youngest
4048

49+
const inventorsByYear = inventors.sort((a, b) => a.year > b.year ? 1 : -1 )
50+
//console.table(inventorsByYear);
51+
52+
4153
// Array.prototype.reduce()
4254
// 4. How many years did all the inventors live?
55+
const totalYears = inventors.reduce(((total, i) => (i.passed - i.year) + total), 0);
56+
//console.log(totalYears);
57+
4358

4459
// 5. Sort the inventors by years lived
4560

61+
const inventorsByAge = inventors
62+
.sort((a, b) => (a.passed - a.year) > (b.passed - b.year) ? -1 : 1)
63+
64+
65+
console.table(inventorsByAge);
66+
4667
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
4768
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
4869

4970

5071
// 7. sort Exercise
5172
// Sort the people alphabetically by last name
5273

74+
5375
// 8. Reduce Exercise
5476
// Sum up the instances of each of these
5577
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
5678

79+
80+
5781
</script>
5882
</body>
5983
</html>

0 commit comments

Comments
 (0)