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 950fa05
Browse filesBrowse the repository at this point in the historyBrowse files
// 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.
79
83
80
-
// Problem 1
84
+
// Problem 1 - For Each, closure, objects, etc...
85
+
// Create an function that returns an object that has the {key :value} pairs as the {size : total number of orders in that size}
86
+
functiongetCountBySize(){
87
+
88
+
//Put all valid sizes in an array
89
+
letsizeArr=["XS","S","M","L","XL","2XL","3XL"];
90
+
91
+
//Create method that increments any size property, parametrically.
92
+
letsizeCount={
93
+
increment : size=>++sizeCount[size]
94
+
};
95
+
96
+
//Initialize all size properties in the object to 0
97
+
sizeArr.forEach(cv=>sizeCount[cv]=0)
98
+
99
+
//Loop through each value in runners, compare with each value in sizeArr, when a match is found, increment that size.
// 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
113
+
// 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
0 commit comments