Skip to content

Commit 258d831

Browse files
committed
completed wesbos#4
1 parent 8dfd008 commit 258d831

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,73 @@
2828
// Array.prototype.filter()
2929
// 1. Filter the list of inventors for those who were born in the 1500's
3030

31+
const fifteenCenturyInventors = inventors.filter(function(inventor){
32+
if(inventor.year > 1500 && inventor.year <1600) {
33+
return true;
34+
}
35+
});
36+
console.table(fifteenCenturyInventors);
37+
3138
// Array.prototype.map()
3239
// 2. Give us an array of the inventory first and last names
40+
const inventorNames = inventors.map(function(inventor){
41+
return inventor.first + " " + inventor.last;
42+
});
43+
44+
console.log(inventorNames);
3345

3446
// Array.prototype.sort()
3547
// 3. Sort the inventors by birthdate, oldest to youngest
3648

49+
const sortedbyBirthdate = inventors.sort(function(a,b){
50+
return a.year > b.year;
51+
});
52+
53+
console.table(sortedbyBirthdate);
54+
3755
// Array.prototype.reduce()
3856
// 4. How many years did all the inventors live?
3957

58+
const yearsLived = inventors.reduce(function(acc,curr){
59+
return acc + (curr.passed - curr.year);
60+
},0);
61+
62+
console.log(yearsLived);
63+
4064
// 5. Sort the inventors by years lived
4165

66+
const sortedByYearsLived = inventors.sort(function(a,b){
67+
return (a.passed - a.year) < (b.passed - b.year);
68+
});
69+
console.table(sortedByYearsLived);
70+
4271
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
4372
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
4473

4574

4675
// 7. sort Exercise
4776
// Sort the people alphabetically by last name
4877

78+
const sortedByLastName = people.sort(function(a,b){
79+
return a > b;
80+
})
81+
82+
console.log(sortedByLastName);
83+
4984
// 8. Reduce Exercise
5085
// Sum up the instances of each of these
5186
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
5287

88+
const transportation = data.reduce(function(obj,item){
89+
if(!obj[item]){
90+
obj[item] = 0;
91+
}
92+
93+
obj[item]++;
94+
return obj;
95+
96+
},{});
97+
console.log(transportation);
5398
</script>
5499
</body>
55100
</html>

0 commit comments

Comments
 (0)