Skip to content

Commit 098a4da

Browse files
committed
wesbos#4 done
1 parent 41ea33d commit 098a4da

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,13 @@
6060

6161
const inventorsByAge = inventors
6262
.sort((a, b) => (a.passed - a.year) > (b.passed - b.year) ? -1 : 1)
63-
64-
63+
.map(i => {
64+
const newObj = {
65+
...i,
66+
age: (i.passed - i.year)
67+
}
68+
return newObj
69+
});
6570
console.table(inventorsByAge);
6671

6772
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
@@ -71,12 +76,27 @@
7176
// 7. sort Exercise
7277
// Sort the people alphabetically by last name
7378

79+
const peopleByLast = people.sort((a, b) => {
80+
const [aLast, aFirst] = a.split(', ');
81+
const [bLast, bFirst] = b.split(', ');
82+
return aLast > bLast ? 1 : -1
83+
})
84+
console.log(peopleByLast);
85+
7486

7587
// 8. Reduce Exercise
7688
// Sum up the instances of each of these
7789
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
7890

91+
const transportation = data.reduce(function(obj, item) {
92+
if (!obj[item]) {
93+
obj[item] = 0;
94+
}
95+
obj[item]++;
96+
return obj;
97+
}, {})
7998

99+
console.log(transportation);
80100

81101
</script>
82102
</body>

0 commit comments

Comments
 (0)