-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
index.js
151 lines (93 loc) · 4.96 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
const { fifaData } = require('./fifa.js')
// ⚽️ M V P ⚽️ //
/* 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 1: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀
Practice accessing data by console.log-ing the following pieces of data note.
💡 HINT: You may want to filter the data first 😉*/
//(a) Home Team name for 2014 world cup final
//(b) Away Team name for 2014 world cup final
//(c) Home Team goals for 2014 world cup final
//(d) Away Team goals for 2014 world cup final
//(e) Winner of 2014 world cup final */
/* 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 2: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀
Use getFinals to do the following:
1. Receive an array as a parameter that will take the fifa data as its argument
2. Return an array of objects with the data of the teams that made it to the final stage
💡 HINT - you should be looking at the stage key inside of the objects
*/
function getFinals(/* code here */) {
/* code here */
}
/* 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 3: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀
Use the higher-order function called getYears to do the following:
1. Receive an array as the first parameter that will take fifaData as an argument
2. Receive a callback function as the second parameter that will take getFinals from task 2 as an argument
3. Return an array called years containing all of the years in the getFinals data set*/
function getYears(/* code here */) {
/* code here */
}
/* 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 4: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀
Use the higher-order function getWinners to do the following:
1. Receive an array as the first parameter that will take fifaData as an argument
2. Receive a callback function as the second parameter that will take getFinals from task 2 as an argument
3. Determines the winner (home or away) of each `finals` game.
💡 HINT: Don't worry about ties for now (Please see the README file for info on ties for a stretch goal.)
4. Returns the names of all winning countries in an array called `winners` */
function getWinners(/* code here */) {
/* code here */
}
/* 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 5: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀
Use the higher-order function getWinnersByYear to do the following:
1. Receive an array as the first parameter that will take fifaData as an argument
2. Receive a callback function as the second parameter that will take getFinals from task 2 as an argument
3. Receive a callback function as the third parameter that will take getYears from task 3 as an argument
4. Receive a callback function as the fourth parameter that will take getWinners from task 4 as an argument
5. Return an array of strings that say "In {year}, {country} won the world cup!"
💡 HINT: the strings returned need to exactly match the string in step 4.
*/
function getWinnersByYear(/* code here */) {
/* code here */
}
/* 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 6: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀
Use the higher order function `getAverageGoals` to do the following:
1. Receive a callback function as a parameter that will take `getFinals` (from task 2) as an argument; ensure you pass in `fifaData` as its argument
💡 HINT: Example of invocation: `getAverageGoals(getFinals(fifaData));`
2. Calculate the AVERAGE number of the TOTAL home team goals AND TOTAL away team goals scored PER MATCH
3. Round to the second decimal place and return the value
💡 HINT: use .reduce, .toFixed (refer to MDN for syntax), and do this in 2 steps)
*/
function getAverageGoals(/* code here */) {
/* code here */
}
/// 🥅 STRETCH 🥅 ///
/* 💪💪💪💪💪 Stretch 1: 💪💪💪💪💪
Create a function called `getCountryWins` that takes the parameters `data` and `team initials` and returns the number of world cup wins that country has had.
Hint: Investigate your data to find "team initials"!
Hint: use `.reduce` */
function getCountryWins(/* code here */) {
/* code here */
}
/* 💪💪💪💪💪 Stretch 2: 💪💪💪💪💪
Write a function called getGoals() that accepts a parameter `data` and returns the team with the most goals score per appearance (average goals for) in the World Cup finals */
function getGoals(/* code here */) {
/* code here */
}
/* 💪💪💪💪💪 Stretch 3: 💪💪💪💪💪
Write a function called badDefense() that accepts a parameter `data` and calculates the team with the most goals scored against them per appearance (average goals against) in the World Cup finals */
function badDefense(/* code here */) {
/* code here */
}
/* If you still have time, use the space below to work on any stretch goals of your chosing as listed in the README file. */
/* 🛑🛑🛑🛑🛑 Please do not modify anything below this line 🛑🛑🛑🛑🛑 */
function foo(){
console.log('its working');
return 'bar';
}
foo();
module.exports = {
foo,
getFinals,
getYears,
getWinners,
getWinnersByYear,
getAverageGoals
}