Skip to content

Commit d25799f

Browse files
committed
complete challenges in array-methods.js
1 parent 019a79e commit d25799f

1 file changed

Lines changed: 26 additions & 5 deletions

File tree

assignments/array-methods.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// A local community center is holding a fund rasising 5k fun run and has invited 50 small businesses to make a small donation on their behalf for some much needed updates to their facilities. Each business has assigned a representative to attend the event along with a small donation.
1+
// A local community center is holding a fund rasising 5k fun run and has invited 50 small businesses to make a small donation on their behalf for some much needed updates to their
2+
// facilities. Each business has assigned a representative to attend the event along with a small donation.
23

34
// Scroll to the bottom of the list to use some advanced array methods to help the event director gather some information from the businesses.
45

@@ -56,28 +57,48 @@ const runners = [{"id":1,"first_name":"Charmain","last_name":"Seiler","email":"c
5657
// ==== Challenge 1: Use .forEach() ====
5758
// 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.
5859
let fullName = [];
60+
runners.forEach(runner => {
61+
fullName.push(runner.first_name + " " + runner.last_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+
allCaps = runners.map(runner => {
69+
runner.first_name = runner.first_name.toUpperCase();
70+
return runner;
71+
});
6472
console.log(allCaps);
6573

6674
// ==== Challenge 3: Use .filter() ====
67-
// 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
75+
// 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.
76+
// Return an array named largeShirts that contains information about the runners that have a shirt size of L and log the result
6877
let largeShirts = [];
78+
largeShirts = runners.filter(runner => runner.shirt_size === "L");
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
73-
let ticketPriceTotal = [];
83+
let ticketPriceTotal = 0;
84+
ticketPriceTotal = runners.reduce((total, currentRunner) => total + currentRunner.donation, 0);
7485
console.log(ticketPriceTotal);
7586

7687
// ==== Challenge 5: Be Creative ====
77-
// Now that you have used .forEach(), .map(), .filter(), and .reduce(). I want you to think of potential problems you could solve given the data set and the 5k fun run theme. Try to create and then solve 3 unique problems using one or many of the array methods listed above.
88+
// Now that you have used .forEach(), .map(), .filter(), and .reduce(). I want you to think of potential problems you could solve given the data set and the 5k fun run theme.
89+
// Try to create and then solve 3 unique problems using one or many of the array methods listed above.
7890

7991
// Problem 1
92+
//Runners who payed more than $100
93+
const moreThan100 = runners.filter(runner => runner.donation >= 100);
94+
console.log(moreThan100);
8095

8196
// Problem 2
97+
// sort last names array
98+
const sortedLastNames = runners.map(runner => runner.last_name).sort();
99+
console.log(sortedLastNames);
82100

83-
// Problem 3
101+
// Problem 3
102+
// Participating companies that payed less than $50
103+
const compLess50 = runners.filter(runner => runner.donation < 50).map(runner => runner.company_name + " $" + runner.donation);
104+
console.log(compLess50);

0 commit comments

Comments
 (0)