Skip to content

Commit 84a643e

Browse files
committed
array-methods completed
1 parent 91ff21a commit 84a643e

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

assignments/array-methods.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,28 +56,53 @@ 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+
runners.forEach(function(runner){
60+
fullName.push(`${runner.first_name} ${runner.last_name}` );
61+
});
5962
console.log(fullName);
6063

6164
// ==== Challenge 2: Use .map() ====
6265
// 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
6366
let allCaps = [];
67+
allCaps = runners.map(x => x.first_name.toUpperCase());
6468
console.log(allCaps);
6569

6670
// ==== Challenge 3: Use .filter() ====
6771
// 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
6872
let largeShirts = [];
73+
largeShirts = runners.filter(x => x.shirt_size === "L");
6974
console.log(largeShirts);
7075

7176
// ==== Challenge 4: Use .reduce() ====
7277
// 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
7378
let ticketPriceTotal = [];
79+
80+
let initalValue = 0;
81+
ticketPriceTotal = runners.reduce(function(accumulator, currentValue){
82+
return accumulator += currentValue.donation;
83+
}, initalValue )
7484
console.log(ticketPriceTotal);
7585

7686
// ==== Challenge 5: Be Creative ====
7787
// 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.
7888

7989
// Problem 1
90+
//Get the company names in alphabetical order.
91+
let companyNames = [];
92+
runners.forEach(function (runner){
93+
companyNames.push(runner.company_name.toLowerCase());
94+
});
95+
console.log(companyNames.sort());
8096

8197
// Problem 2
98+
//Get donation for every runner over 200 Each runner that got over 200 donation gets a special certificate to say thanks. Need to send out email Get email address for each runner over 200.
99+
let y = false;
100+
let bigDonations = [];
101+
runners.filter( x => x.donation > 200 ? bigDonations.push(x.email) : y=false );
102+
console.log(bigDonations);
103+
104+
105+
// Problem 3 taxes on the donations is 7% or .07 calculate the tax for each runners donation and then added it to their information.
82106

83-
// Problem 3
107+
runners.map(x => x.taxes = x.donation*.07);
108+
console.log(runners);

0 commit comments

Comments
 (0)