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 24d8f97
Browse filesBrowse the repository at this point in the historyBrowse files
// 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
// 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
79
letlargeShirts=[];
80
+
largeShirts.push(runners.filter((name)=>{
81
+
82
+
if(name["shirt-size"]==="L"){
83
+
84
+
returnname;
85
+
86
+
}
87
+
88
+
}))
89
+
69
90
console.log(largeShirts);
70
91
71
92
// ==== Challenge 4: Use .reduce() ====
72
93
// 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.
78
106
79
107
// Problem 1
108
+
//Manager Needs all the Emails
109
+
110
+
letEmails=[]
111
+
112
+
Emails.push(runners.forEach(function(item){
113
+
114
+
returnitem["email"];
115
+
116
+
}));
117
+
80
118
81
119
// Problem 2
82
120
83
-
// Problem 3
121
+
// Who are the people that need XS shirts.
122
+
123
+
constXSShirts=[];
124
+
125
+
XSShirts.push(runners.filter(function(object){
126
+
127
+
if(object.shirt_size==="XS"){
128
+
129
+
console.log(`${object.first_name}${object.last_name} needs a ${object.shirt_size}`);
// Create a higher order function and invoke the callback function to test your work. You have been provided an example of a problem and a solution to see how this works with our items array. Study both the problem and the solution to figure out the rest of the problems.
1
+
// Create a callback function and invoke the function to test your work. You have been provided an example of a problem and a solution to see how this works with our items array. Study both the problem and the solution to figure out the rest of the problems.
2
2
3
3
constitems=['Pencil','Notebook','yo-yo','Gum'];
4
-
5
4
/*
6
-
7
5
//Given this problem:
8
6
9
7
function firstItem(arr, cb) {
10
8
// firstItem passes the first item of the given array to the callback function.
11
9
}
12
-
13
10
// Potential Solution:
14
-
15
-
// Higher order function using "cb" as the call back
16
11
function firstItem(arr, cb) {
17
12
return cb(arr[0]);
18
13
}
19
-
20
-
// Function invocation
21
14
firstItem(items, function(first) {
22
15
console.log(first)
23
16
});
24
-
25
17
*/
26
18
27
-
28
19
functiongetLength(arr,cb){
29
20
// getLength passes the length of the array into the callback.
21
+
returncb(arr.length);
30
22
}
31
23
24
+
getLength(items,function(length){
25
+
console.log(length);
26
+
});
27
+
28
+
32
29
functionlast(arr,cb){
33
30
// last passes the last item of the array into the callback.
31
+
returncb(arr[arr.length-1]);
34
32
}
35
33
34
+
last(items,function(last){
35
+
console.log(last);
36
+
});
37
+
38
+
36
39
functionsumNums(x,y,cb){
37
40
// sumNums adds two numbers (x, y) and passes the result to the callback.
41
+
constsum=x+y;
42
+
returncb(sum);
38
43
}
39
44
45
+
sumNums(3,6,function(sum){
46
+
console.log(sum);
47
+
});
48
+
49
+
40
50
functionmultiplyNums(x,y,cb){
41
51
// multiplyNums multiplies two numbers and passes the result to the callback.
52
+
constproduct=x*y;
53
+
returncb(product);
42
54
}
43
55
56
+
multiplyNums(3,6,function(product){
57
+
console.log(product);
58
+
});
59
+
60
+
44
61
functioncontains(item,list,cb){
45
62
// contains checks if an item is present inside of the given array/list.
46
63
// Pass true to the callback if it is, otherwise pass false.
64
+
if(list.includes(item)==true){
65
+
returncb(true);
66
+
}else{
67
+
returncb(false);
68
+
}
47
69
}
48
70
71
+
contains('Notebook',items,function(included){
72
+
console.log(included);
73
+
});
74
+
49
75
/* STRETCH PROBLEM */
50
76
51
77
functionremoveDuplicates(array,cb){
52
78
// removeDuplicates removes all duplicate values from the given array.
53
79
// Pass the duplicate free array to the callback function.
0 commit comments