Skip to content

Commit a053f17

Browse files
committed
Challenges 1-4 of array methods
1 parent 190b5cd commit a053f17

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

assignments/array-methods.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,24 @@ const runners = [{"id":1,"first_name":"Charmain","last_name":"Seiler","email":"c
5656
// ==== Challenge 1: Use .forEach() ====
5757
// The event director needs both the first and last names of each runner for their running bibs. Combine both the first and last names into a new array called fullName.
5858
let fullName = [];
59+
runners.forEach(function(runner) {
60+
fullName.push(`${runner.first_name} ${runner.last_name}`);
61+
});
5962
console.log(fullName);
6063

6164
// ==== Challenge 2: Use .map() ====
6265
// 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
63-
let allCaps = [];
66+
let allCaps = runners.map(runner => runner.first_name.toUpperCase());
6467
console.log(allCaps);
6568

6669
// ==== Challenge 3: Use .filter() ====
6770
// 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. Return an array named largeShirts that contains information about the runners that have a shirt size of L and log the result
68-
let largeShirts = [];
71+
let largeShirts = runners.filter(runner => runner.shirt_size === "L");
6972
console.log(largeShirts);
7073

7174
// ==== Challenge 4: Use .reduce() ====
7275
// 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
73-
let ticketPriceTotal = [];
76+
let ticketPriceTotal = runners.reduce((total, runner) => (total + runner.donation), 0);
7477
console.log(ticketPriceTotal);
7578

7679
// ==== Challenge 5: Be Creative ====

0 commit comments

Comments
 (0)