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
{{ message }}
Repository navigation
Commit ebd26ac
Browse filesBrowse the repository at this point in the historyBrowse files
// Create a function getDonationMetricsBySize, For each size, find the min, max, avg and total donations and store into an object that can get any value via dot
112
-
// notation
111
+
// Create a function getDonationMetricsBySize that has one parameter (size). The size parameter can be "s", "m", "l", "xl", "xxl", etc.
112
+
// For a given size, the function should be able to return the min, max, avg and total donations for the given size, via dot notation.
113
+
//
113
114
// For example
114
-
// getDonationMetricsBySize("xl").xl.avg should give you the average donation for size XL
115
-
// getDonationMetricsBySize("m").m.min should give you the minimum donation for size M
116
-
// getDonationMetricsBySize("s").s.max should give you the maximum donation for size S
117
-
// getDonationMetricsBySize("xxxl").xxxl.total should give you the total donation for size XXXL
118
-
// TODO get it working for XXL and XXXL
115
+
// getDonationMetricsBySize("xl").xl.avg => should give you the average donation for size XL
116
+
// getDonationMetricsBySize("m").m.min => should give you the minimum donation for size M
117
+
// getDonationMetricsBySize("s").s.max => should give you the maximum donation for size S
118
+
// getDonationMetricsBySize("xxxl").xxxl.total => should give you the total donation for size 3XL
119
119
120
120
functiongetDonationMetricsBySize(size){
121
121
122
+
//Make a deep copy
122
123
letrunnersMod=runners.map(cv=>cv);
123
-
// if (cv.shirt_size === "2XL") {
124
-
// return arr.shirt_size === "XXL"
125
-
// }else if (cv.shirt_size === "2XL"){
126
-
// return arr.shirt_size === "XXXL"
127
-
// }
128
-
// console.log(runnersMod.length)
129
-
130
-
// console.log(runnersMod)
131
-
// console.log(runnersMod)
124
+
125
+
// Remove 2XL and 3XL with XXL and XXXL as they can't be Object keys (starting with numbers).
126
+
for(i=0;i<runnersMod.length;i++){
127
+
if(runnersMod[i].shirt_size==="2XL"){
128
+
runnersMod[i].shirt_size="XXL"
129
+
}elseif(runnersMod[i].shirt_size==="3XL"){
130
+
runnersMod[i].shirt_size="XXXL"
131
+
}
132
+
}
132
133
133
-
//Initialize the object
134
+
//Initialize the Dontation by Size object
134
135
letdonateBySize={
135
136
xs : {min:0,max:0,total:0,avg:0},
136
137
s : {min:0,max:0,total:0,avg:0},
@@ -141,20 +142,20 @@ function getDonationMetricsBySize(size){
0 commit comments