Skip to content

Commit ff5909d

Browse files
Task 4: array methods.js mostly complete
1 parent 561afd6 commit ff5909d

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

‎assignments/array-methods.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,32 @@ 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(runner => {
60+
return fullName.push(`${runner.first_name} ${runner.last_name}`)});
61+
/*runners.forEach(function(runner){
62+
fullName.push(`${runner.first_name} ${runner.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
6368
let allCaps = [];
69+
allCaps = runners.map(runner => {
70+
return runner.first_name.toUpperCase()});
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(runner => {
77+
return runner.shirt_size === "L"});
6978
console.log(largeShirts);
7079

7180
// ==== Challenge 4: Use .reduce() ====
7281
// 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
7382
let ticketPriceTotal = [];
83+
ticketPriceTotal = runners.reduce((accum, runner) => {
84+
return accum += runner.donation}, 0);
7485
console.log(ticketPriceTotal);
7586

7687
// ==== Challenge 5: Be Creative ====

0 commit comments

Comments
 (0)