Skip to content

Commit 23365f8

Browse files
committed
Finished array-method.js
1 parent afae86b commit 23365f8

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

assignments/array-methods.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,30 +54,39 @@ const runners = [{"id":1,"first_name":"Charmain","last_name":"Seiler","email":"c
5454
{"id":50,"first_name":"Shell","last_name":"Baine","email":"[email protected]","shirt_size":"M","company_name":"Gabtype","donation":171}];
5555

5656
// ==== Challenge 1: Use .forEach() ====
57-
// 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.
57+
// 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(x => fullName.push(x.first_name +" "+ x.last_name))
5960
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
63-
let allCaps = [];
64-
console.log(allCaps);
64+
let allCaps = runners.map(x => x.first_name.toUpperCase());
65+
console.log(allCaps);
6566

6667
// ==== Challenge 3: Use .filter() ====
6768
// 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
68-
let largeShirts = [];
69+
let largeShirts = runners.filter(x => x.shirt_size === "L");
6970
console.log(largeShirts);
7071

71-
// ==== Challenge 4: Use .reduce() ====
72+
// ==== Challenge 4: Use .reduce() ====0
7273
// 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 = [];
74+
let ticketPriceTotal = runners.reduce((a, b) => a + b.donation,0);
7475
console.log(ticketPriceTotal);
7576

7677
// ==== Challenge 5: Be Creative ====
7778
// 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.
7879

7980
// Problem 1
80-
81+
// Each participant gets a shirt with thier company logo paired with the logo for the fun run
82+
let logoShirt = [];
83+
runners.forEach(x => logoShirt.push(x.company_name +" x "+"5k fun run"));
84+
console.log(logoShirt);
8185
// Problem 2
82-
83-
// Problem 3
86+
// If a participant donated more then 150 they get a raffle ticket
87+
let raffleTicket = runners.filter(x => x.donation > 150);
88+
console.log(raffleTicket);
89+
// Problem 3
90+
// database needs all email capitalized
91+
let emailCaps = runners.map(x => x.email.toUpperCase());
92+
console.log(emailCaps)

0 commit comments

Comments
 (0)