Skip to content

Commit 6c7b8e2

Browse files
committed
chore: Complete challenge 5
1 parent f2ee355 commit 6c7b8e2

1 file changed

Lines changed: 34 additions & 5 deletions

File tree

‎assignments/array-methods.js‎

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ runners.forEach(runner => {
6060
let runnerFullName = `${runner.first_name} ${runner.last_name}`;
6161
fullName.push(runnerFullName);
6262
})
63-
console.log(fullName);
63+
// console.log(fullName);
6464

6565
// ==== Challenge 2: Use .map() ====
6666
// 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
@@ -69,27 +69,56 @@ fullName.map(runnerName => {
6969
let uppercaseFirstName = runnerName.split(' ')[0].toUpperCase();
7070
allCaps.push(`${uppercaseFirstName} ${runnerName.split(' ')[1]}`)
7171
})
72-
console.log(allCaps);
72+
// console.log(allCaps);
7373

7474
// ==== Challenge 3: Use .filter() ====
7575
// 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
7676
let largeShirts = [];
7777
largeShirts = runners.filter(runner => runner.shirt_size === 'L');
78-
console.log(largeShirts);
78+
// console.log(largeShirts);
7979

8080
// ==== Challenge 4: Use .reduce() ====
8181
// 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
8282
let ticketPriceTotal = [];
8383
ticketPriceTotal = runners.reduce((total, runner) => {
8484
return total + runner.donation;
8585
}, 0)
86-
console.log(ticketPriceTotal);
86+
// console.log(ticketPriceTotal);
8787

8888
// ==== Challenge 5: Be Creative ====
8989
// 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.
9090

9191
// Problem 1
92+
// Return new array with people from the same company
93+
let companyName = "Wordtune";
94+
let workColleagues = [];
95+
workColleagues = runners.filter(runner => runner.company_name === companyName);
96+
// console.log(workColleagues)
9297

9398
// Problem 2
99+
// Number of people who donated X amount
100+
let definedAmount = 200;
101+
let superDonators = [];
102+
superDonators = runners.filter(runner => runner.donation >= definedAmount);
103+
// console.log(`We got ${superDonators.length} super donators`);
94104

95-
// Problem 3
105+
// Problem 3
106+
// List all email
107+
const runnersEmail = [];
108+
runners.map(runner => {
109+
runnersEmail.push(runner.email);
110+
})
111+
112+
console.log(runnersEmail);
113+
114+
115+
// Return total of each shirt size // Wanted to try something fancy. Will take a look again.
116+
/* const temp = {};
117+
const shirtGroupings = runners.reduce((shirtGroup, runner) => {
118+
if (!temp[runner.shirt_size]) {
119+
shirtGroup.push(runner.shirt_size)
120+
}
121+
return shirtGroup;
122+
}, []);
123+
*/
124+
// console.log(shirtGroupings);

0 commit comments

Comments
 (0)