1 parent 2e66109 commit 4e32d64Copy full SHA for 4e32d64
1 file changed
04 - Array Cardio Day 1/answers.js
@@ -57,9 +57,30 @@ console.log(oldest);
57
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
58
59
60
+//Array.from
61
+
62
// 7. sort Exercise
63
// Sort the people alphabetically by last name
64
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
73
// 8. Reduce Exercise
74
// Sum up the instances of each of these
-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