Skip to content

Commit ca88731

Browse files
committed
complete array-methods.js challenge 5
1 parent 693b7b8 commit ca88731

File tree

1 file changed

+60
-2
lines changed

1 file changed

+60
-2
lines changed

assignments/array-methods.js

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ console.log(fullNames);
6666
// ==== Challenge 2: Use .map() ====
6767
// The event director needs to have all the runners' first names in uppercase because the director BECAME DRUNK WITH POWER. Populate an array called `firstNamesAllCaps`. This array will contain just strings.
6868
let firstNamesAllCaps = [];
69-
runners.forEach(runnersArr => {
69+
runners.map(runnersArr => {
7070
firstNamesAllCaps.push(`${runnersArr.first_name.toUpperCase()}`)
7171
});
7272
console.log(firstNamesAllCaps);
@@ -103,6 +103,64 @@ console.log(ticketPriceTotal);
103103

104104
// Problem 1
105105

106+
//Compute all data of all the ruuner using forEach
107+
let runnerDetails = [];
108+
runners.forEach(runnersArr => {
109+
runnerDetails.push(`Full Name: ${runnersArr.first_name} ${runnersArr.last_name}.
110+
Email: ${runnersArr.email}.
111+
Shirt Size: ${runnersArr.shirt_size}.
112+
Company Name: ${runnersArr.company_name}.
113+
Donations: ${runnersArr.donation}`)
114+
});
115+
console.log(runnerDetails);
116+
117+
106118
// Problem 2
107119

108-
// Problem 3
120+
//Compute the percentage donated by each runner using Map
121+
let pecentageDonatedByRunner = [];
122+
function pecentageDonated(runnersArr) {
123+
donationInPercentage = (((runnersArr.donation / ticketPriceTotal) * 100).toFixed(2))
124+
pecentageDonatedByRunner.push(`${runnersArr.first_name} ${runnersArr.last_name} donated ${donationInPercentage}% of the total donations recieved`)
125+
return pecentageDonatedByRunner;
126+
}
127+
runners.map(pecentageDonated)
128+
console.log(pecentageDonatedByRunner)
129+
130+
131+
// Problem 3
132+
133+
//Compute all runners first name starting with "S" using Filter
134+
let runnersNames = [];
135+
function filterRunnersNames(runnersArr) {
136+
if(runnersArr.first_name[0] === "S") {
137+
runnersNames.push(`${runnersArr.first_name} ${runnersArr.last_name}`);
138+
}
139+
return runnersNames
140+
}
141+
runners.filter(filterRunnersNames)
142+
console.log(runnersNames);
143+
144+
145+
//problem 4
146+
147+
//compute total average donation for all runners using Reduce
148+
let totalAverageDonations = 0;
149+
function totalDonations2(initialDonation, currentDonation) {
150+
totalAverageDonations = initialDonation + currentDonation.donation;
151+
return totalAverageDonations
152+
}
153+
// console.log(runners.reduce(totalDonations, 0))
154+
runners.reduce(totalDonations2, 0)
155+
console.log(totalAverageDonations/(runners.length));
156+
157+
158+
// const euros = [29.76, 41.85, 46.5];
159+
// const average = euros.reduce((total, amount, index, array) => {
160+
// total += amount;
161+
// if( index === array.length-1) {
162+
// return total/array.length;
163+
// }else {
164+
// return total;
165+
// }
166+
// });

0 commit comments

Comments
 (0)