Skip to content

Commit 4e32d64

Browse files
committed
pogo stick
1 parent 2e66109 commit 4e32d64

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

04 - Array Cardio Day 1/answers.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,30 @@ console.log(oldest);
5757
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
5858

5959

60+
//Array.from
61+
6062
// 7. sort Exercise
6163
// Sort the people alphabetically by last name
6264

65+
const alpha = people.sort(function(lastOne, nextOne) {
66+
const [aLast, aFirst] = lastOne.split(', ');
67+
const [bLast, bFirst] = nextOne.split(', ');
68+
return aLast > bLast ? 1 : -1;
69+
});
70+
71+
console.log(alpha);
72+
6373
// 8. Reduce Exercise
6474
// Sum up the instances of each of these
65-
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
75+
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck', 'pogostick' ];
76+
77+
78+
const transportation = data.reduce(function(obj, item) {
79+
if(!obj[item]) {
80+
obj[item] = 0;
81+
}
82+
obj[item]++;
83+
return obj;
84+
}, {});
85+
86+
console.log(transportation);

0 commit comments

Comments
 (0)