Skip to content

Commit 1e43163

Browse files
committed
solves challenge-4 in array-methods.js
1 parent 4a422ac commit 1e43163

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

assignments/array-methods.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@ console.log(fullName);
6262

6363
// ==== Challenge 2: Use .map() ====
6464
// The event director needs to have all the runner's first names converted to uppercase because the director BECAME DRUNK WITH POWER. Convert each first name into all caps and log the result
65-
let allCaps = [];
6665

67-
allCaps = runners.map(runner => {
66+
let allCaps = runners.map(runner => {
6867
var newRunner = {};
6968
return newRunner.first_name = runner.first_name.toUpperCase();
7069
});
@@ -75,21 +74,26 @@ console.log(allCaps);
7574
// ==== Challenge 3: Use .filter() ====
7675
// The large shirts won't be available for the event due to an ordering issue. Get a list of runners with large sized shirts so they can choose a different size.
7776
// Return an array named largeShirts that contains information about the runners that have a shirt size of L and log the result
78-
let largeShirts = [];
7977

80-
largeShirts = runners.filter(runner => {return runner.shirt_size === "L"});
78+
let largeShirts = runners.filter(runner => {return runner.shirt_size === "L"});
8179

8280
console.log(largeShirts);
8381

8482
// ==== Challenge 4: Use .reduce() ====
8583
// The donations need to be tallied up and reported for tax purposes. Add up all the donations into a ticketPriceTotal array and log the result
86-
let ticketPriceTotal = [];
87-
console.log(ticketPriceTotal);
84+
85+
let ticketPriceTotal = runners.reduce((ticketPriceSum, runner ) => ticketPriceSum + runner.donation, 0);
86+
87+
console.log("$" + ticketPriceTotal);
88+
8889

8990
// ==== Challenge 5: Be Creative ====
90-
// 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.
91+
// 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.
92+
// Try to create and then solve 3 unique problems using one or many of the array methods listed above.
9193

9294
// Problem 1
95+
//It turns out that some of the runners are actually dogs: Gussy, Fidel and Dollie. Please add for each runner whether the runner is a human or a dog.
96+
9397

9498
// Problem 2
9599

0 commit comments

Comments
 (0)