Skip to content

Commit 66b98a6

Browse files
committed
Almost finished with array-methods. Just need to finish Challenge 5: Be Creative
1 parent 7c58b44 commit 66b98a6

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

assignments/array-methods.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,28 +56,36 @@ 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-
console.log(fullName);
59+
runners.forEach((i) => fullName.push(i.first_name + " " + i.last_name))
60+
// console.log(fullName);
6061

6162
// ==== Challenge 2: Use .map() ====
6263
// 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
6364
let allCaps = [];
64-
console.log(allCaps);
65+
runners.map((i) => allCaps.push(i.first_name.toUpperCase()))
66+
// console.log(allCaps);
6567

6668
// ==== Challenge 3: Use .filter() ====
6769
// 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
6870
let largeShirts = [];
69-
console.log(largeShirts);
71+
largeShirts = runners.filter((i) => (i.shirt_size === 'L'))
72+
//console.log(largeShirts);
7073

7174
// ==== Challenge 4: Use .reduce() ====
7275
// 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
7376
let ticketPriceTotal = [];
77+
let initialValue = 0;
78+
ticketPriceTotal.push(runners.reduce((acc, currentValue) => acc + currentValue.donation , initialValue))
7479
console.log(ticketPriceTotal);
7580

7681
// ==== Challenge 5: Be Creative ====
7782
// 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 solve 3 unique problems using one or many of the array methods listed above.
7883

7984
// Problem 1
85+
// Count the instances of people working at the same company. (More than one company: Wordtune 2, Gigashots 2, Skinte 2, Skinix 3, Kwimbee 2)
8086

8187
// Problem 2
88+
// Combine the ids and emails
8289

83-
// Problem 3
90+
// Problem 3
91+
// Alphebatize the runners based on last name

0 commit comments

Comments
 (0)