You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// A local community center is holding a fund rasising 5k fun run and has invited 50 small businesses to make a small donation on their behalf for some much needed updates to their facilities. Each business has assigned a representative to attend the event along with a small donation.
1
+
// // A local community center is holding a fund rasising 5k fun run and has invited 50 small businesses to make a small donation on their behalf for some much needed updates to their facilities. Each business has assigned a representative to attend the event along with a small donation.
2
2
3
-
// Scroll to the bottom of the list to use some advanced array methods to help the event director gather some information from the businesses.
3
+
// // Scroll to the bottom of the list to use some advanced array methods to help the event director gather some information from the businesses.
// 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.
// 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
-
letallCaps=[];
64
-
console.log(allCaps);
64
+
// // // ==== Challenge 2: Use .map() ====
65
+
// // // 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
66
+
letallCaps=runners.map(function(runner){
67
+
returnrunner.first_name.toUpperCase();
68
+
})
65
69
66
-
// ==== Challenge 3: Use .filter() ====
67
-
// 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
-
letlargeShirts=[];
69
-
console.log(largeShirts);
70
+
console.log(`\nChallenge 2 Output:\n${allCaps}`);
70
71
71
-
// ==== Challenge 4: Use .reduce() ====
72
-
// 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
-
letticketPriceTotal=[];
74
-
console.log(ticketPriceTotal);
72
+
// // // ==== Challenge 3: Use .filter() ====
73
+
// // // 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
74
+
letlargeShirts=runners.filter(function(runner){
75
+
if(runner.shirt_size=='L'){
76
+
returnrunner;
77
+
}
78
+
});
79
+
letvalues=JSON.stringify(largeShirts);
75
80
76
-
// ==== Challenge 5: Be Creative ====
77
-
// 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.
78
81
79
-
// Problem 1
82
+
console.log(`\nChallenge 3 Output:\n${values}`);
83
+
84
+
// // // ==== Challenge 4: Use .reduce() ====
85
+
// // // 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
// // // 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.
96
+
97
+
// // // Problem 1 - We've been hacked! It was someone from an @example.com domain address, can you find it? Return array with the persons info where there are any @example.com addresses.
98
+
99
+
console.log('\nChallenge 5 - Problem 1 Output:')
100
+
constaddresses=runners.filter(function(runner){
101
+
letdomain=runner.email.split('@');
102
+
if(domain.includes('example.com')){
103
+
returntrue;
104
+
}
105
+
});
106
+
107
+
addresses.forEach(function(item){
108
+
console.log(item);
109
+
})
110
+
111
+
// // // Problem 2 - We need more sponsers. Put together a list of all the runners who donated 200 dollars or more. Then add up their total donations, log the list and total. We're going to try and throw them an appreciation party in the most public way possible. Just want to see if we can afford it.
112
+
113
+
constdonors=runners.filter(function(donor){
114
+
if(donor.donation>=200){
115
+
returntrue;
116
+
}
117
+
});
118
+
consttotal=donors.reduce(function(acc,val){
119
+
returnacc+val.donation;
120
+
},0);
121
+
122
+
console.log(`\nChallenge 5 - Problem 2 Output:`)
123
+
124
+
donors.forEach(function(donor){
125
+
console.log(donor);});
126
+
127
+
console.log(`\nTotal Donations :$${total}`);
128
+
129
+
// // // Problem 3 - In preparation for the race, we want to try and oranize the runners at the starting line according to who passed the benchmark run or not. For each runner include an entry called 'benchmark' and state whether they passed or failed. Return the array and how many people passed the benchmark.
130
+
131
+
functionincludeBenchmark(){
132
+
letvalue=Number(Math.random()*1).toFixed();
133
+
if(value==1){
134
+
return'Passed';
135
+
}
136
+
else{
137
+
return'Failed';
138
+
}
139
+
}
140
+
141
+
constbenchmarkers=runners.map(function(runner){
142
+
143
+
returnObject.defineProperty(runner,'benchmark',{
144
+
value: includeBenchmark(),
145
+
writable: false,
146
+
enumerable: true
147
+
})
148
+
});
149
+
150
+
151
+
functionpassers(arr=benchmarkers){
152
+
lettotalPassed=0;
153
+
arr.forEach(function(runner){
154
+
if(runner.benchmark=='Passed'){
155
+
totalPassed++;
156
+
}
157
+
})
158
+
returntotalPassed;
159
+
}
160
+
161
+
letnewarray=JSON.stringify(benchmarkers);
162
+
console.log(`Challenge 5 - Problem 3 Output:\n ${benchmarkers} \nThe total number of runners who passed is ${passers()}`);
0 commit comments