Skip to content

Commit 03c3396

Browse files
author
Sheila R Moore
committed
completed array-methods.js
1 parent fc02465 commit 03c3396

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

assignments/array-methods.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,28 +56,60 @@ 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 (value){
60+
fullName.push(value.first_name + ` ` + value.last_name);
61+
})
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+
69+
runners.map(function(value){
70+
console.log(value.first_name.toUpperCase());
71+
})
6472
console.log(allCaps);
6573

6674
// ==== Challenge 3: Use .filter() ====
6775
// 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
6876
let largeShirts = [];
77+
78+
largeShirts.push(runners.filter(runner => runner.shirt_size == "L" ));
79+
6980
console.log(largeShirts);
7081

7182
// ==== Challenge 4: Use .reduce() ====
7283
// 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
7384
let ticketPriceTotal = [];
85+
runners.reduce(function (accumulator, value) {
86+
console.log(`the accumulator ${accumulator}`);
87+
console.log(` the value ${value.donation}`);
88+
return accumulator + value.donation;
89+
}, 0);
90+
7491
console.log(ticketPriceTotal);
7592

7693
// ==== Challenge 5: Be Creative ====
7794
// 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.
7895

7996
// Problem 1
97+
// Find all the small shirts
98+
let smallShirts = [];
8099

81-
// Problem 2
100+
smallShirts.push(runners.filter(runner => runner.shirt_size == "S" ));
82101

83-
// Problem 3
102+
console.log(smallShirts);
103+
104+
// Problem 2
105+
//Find all the emails
106+
let emailList =[];
107+
emailList.push(runners.map(runner => runner.email));
108+
console.log(emailList);
109+
// Problem 3
110+
//Name and Donation
111+
let nameDonation =[];
112+
runners.forEach(runner => {
113+
nameDonation.push(`${runner.first_name} ${runner.donation}`);
114+
});
115+
console.log(nameDonation)

0 commit comments

Comments
 (0)