Skip to content

Commit db6af5e

Browse files
committed
finished array methods
1 parent e371a56 commit db6af5e

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

assignments/array-methods.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,32 @@ console.log(ticketPriceTotal);
9090
// ==== Challenge 5: Be Creative ====
9191
// Now that you have used .forEach(), .map(), .filter(), and .reduce(). I want you to think of potential problems you could solve given the data set and the 5k fun run theme. Try to create and then solve 3 unique problems using one or many of the array methods listed above.
9292

93-
// Problem 1
93+
// Problem 1 Kick out the rich people by excluding donations larger than 200
9494

95-
// Problem 2
95+
let remainingRunners = runners.filter( function(runnerObj) {
96+
return runnerObj.donation < 200;
97+
})
98+
99+
// Problem 2 combine everyones last name
100+
101+
const reducer2 = function(acc, runnerObj) {
102+
return acc + runnerObj.last_name;
103+
}
104+
105+
let hugeLastName = runners.reduce(reducer2, '');
106+
console.log(hugeLastName);
107+
108+
// Problem 3 Get #s for each shirt size
109+
110+
let shirtSizeCount = {}
111+
112+
runners.forEach( function(runnerObj) {
113+
let size = runnerObj.shirt_size;
114+
if(!shirtSizeCount[size]) {
115+
shirtSizeCount[runnerObj.shirt_size] = 1;
116+
} else {
117+
shirtSizeCount[runnerObj.shirt_size]++;
118+
}
119+
})
96120

97-
// Problem 3
121+
console.log(JSON.stringify(shirtSizeCount));

0 commit comments

Comments
 (0)