Skip to content

Commit 418fafc

Browse files
committed
array method exercise complete
1 parent a9c5b2c commit 418fafc

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

assignments2/array-methods.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,34 @@ 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+
let name = `${runner.first_name} ${runner.last_name}`;
61+
fullName.push(name);
62+
})
5963
console.log(fullName);
6064

6165
// ==== Challenge 2: Use .map() ====
6266
// 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
6367
let allCaps = [];
68+
runners.map(function(runner) {
69+
allCaps.push(runner.first_name.toUpperCase());
70+
})
6471
console.log(allCaps);
6572

6673
// ==== Challenge 3: Use .filter() ====
6774
// 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
6875
let largeShirts = [];
76+
largeShirts = runners.filter(function(runner) {
77+
return runner.shirt_size === "L";
78+
})
6979
console.log(largeShirts);
7080

7181
// ==== Challenge 4: Use .reduce() ====
7282
// 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
7383
let ticketPriceTotal = [];
84+
ticketPriceTotal = runners.reduce(function(total, runner) {
85+
return total + runner.donation;
86+
}, 0)
7487
console.log(ticketPriceTotal);
7588

7689
// ==== Challenge 5: Be Creative ====

0 commit comments

Comments
 (0)