Skip to content

Commit a4547f3

Browse files
committed
1-4 finished
1 parent 1435bd4 commit a4547f3

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

assignments/array-methods.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,33 +57,31 @@ const runners = [{"id":1,"first_name":"Charmain","last_name":"Seiler","email":"c
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 = [];
5959
runners.forEach(function(i) {
60-
fullName.push(runners[i].first_name + runners[i].last_name);
61-
return fullName;
60+
return fullName.push(i.first_name + i.last_name);
6261
});
6362
console.log(fullName);
6463

6564
// ==== Challenge 2: Use .map() ====
6665
// 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
67-
let allCaps = [];
68-
runners.map(function(i) {
69-
allCaps.toUpperCase(runners[i].first_name).push(runners[i].first_name);
70-
return allCaps;
66+
let allCaps = runners.map(function(i) {
67+
return i.first_name.toUpperCase();
7168
});
7269

7370
console.log(allCaps);
7471

7572
// ==== Challenge 3: Use .filter() ====
7673
// 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
77-
let largeShirts = [];
78-
runners.filter(function() {
79-
largeShirts.push(runners.shirt_size === 'L');
80-
return largeShirts;
74+
let largeShirts = runners.filter((data, i, runners) => {
75+
return data.shirt_size === 'L';
76+
8177
});
8278
console.log(largeShirts);
8379

8480
// ==== Challenge 4: Use .reduce() ====
8581
// 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 = [];
82+
let ticketPriceTotal = runners.reduce((theReducer, item) => {
83+
return theReducer += item.donation;
84+
}, 0);
8785
console.log(ticketPriceTotal);
8886

8987
// ==== Challenge 5: Be Creative ====
@@ -93,4 +91,6 @@ console.log(ticketPriceTotal);
9391

9492
// Problem 2
9593

96-
// Problem 3
94+
// Problem 3
95+
96+

0 commit comments

Comments
 (0)