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
// 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.
58
58
letfullName=[];
59
-
console.log(fullName);
59
+
runners.forEach(function(obj){
60
+
fullName.push([obj.first_name+obj.last_name])
61
+
returnfullName;
62
+
})
63
+
//console.log(fullName);
64
+
60
65
61
66
// ==== Challenge 2: Use .map() ====
62
67
// 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
68
letallCaps=[];
64
-
console.log(allCaps);
69
+
runners.map(function(obj){
70
+
allCaps.push(obj.first_name.toUpperCase());
71
+
})
72
+
//console.log(allCaps);
65
73
66
74
// ==== Challenge 3: Use .filter() ====
67
75
// 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
76
letlargeShirts=[];
69
-
console.log(largeShirts);
77
+
runners.filter(function(obj){
78
+
if(obj.shirt_size==="L"){
79
+
largeShirts.push(obj)
80
+
}
81
+
returnlargeShirts;
82
+
})
83
+
//console.log(largeShirts);
70
84
71
85
// ==== Challenge 4: Use .reduce() ====
72
86
// 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);
87
+
88
+
letticketPriceTotal=
89
+
runners.reduce(function(total,runner){
90
+
returntotal+runner.donation
91
+
},0)
92
+
93
+
94
+
runners.reduce((total,runner)=>{
95
+
returntotal+runner.donation
96
+
},0)
97
+
98
+
99
+
100
+
//console.log(ticketPriceTotal)
101
+
75
102
76
103
// ==== Challenge 5: Be Creative ====
77
104
// 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.
0 commit comments