Skip to content

Commit 3c7a54f

Browse files
Cameron RayCameron Ray
authored andcommitted
array-methods challenges 1-3 complete
1 parent 638d7c4 commit 3c7a54f

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

assignments/array-methods.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,38 @@ const runners = [{"id":1,"first_name":"Charmain","last_name":"Seiler","email":"c
5555

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.
58+
console.log("\nChallenge 1:");
5859
let fullName = [];
60+
61+
runners.forEach(function(element) {
62+
fullName.push(element["first_name"] + " " + element["last_name"]);
63+
});
5964
console.log(fullName);
6065

6166
// ==== Challenge 2: Use .map() ====
6267
// 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 = [];
68+
console.log("\nChallenge 2:");
69+
let allCaps = runners.map(function(runner) {
70+
return runner["first_name"].toUpperCase();
71+
});
72+
6473
console.log(allCaps);
6574

6675
// ==== Challenge 3: Use .filter() ====
6776
// 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 = [];
77+
console.log("\nChallenge 3:");
78+
let largeShirts = runners.filter(function(runner) {
79+
return runner["shirt_size"] === "L";
80+
});
6981
console.log(largeShirts);
7082

7183
// ==== Challenge 4: Use .reduce() ====
7284
// 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 = [];
85+
console.log("\nChallenge 4:");
86+
let ticketPriceTotal = runners.reduce(function(reducer, runner) {
87+
return reducer += runner["donation"];
88+
});
89+
7490
console.log(ticketPriceTotal);
7591

7692
// ==== Challenge 5: Be Creative ====

0 commit comments

Comments
 (0)