Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first commit #224

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 49 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,30 @@ Practice accessing data by console.log-ing the following pieces of data note.

💡 HINT: You may want to filter the data first 😉*/

const finals2014 = fifaData.filter(function(match){
return match.Year === 2014 && match.Stage === 'Final'
});
console.log(finals2014);

//(a) Home Team name for 2014 world cup final

console.log(finals2014[0]["Home Team Name"]);

//(b) Away Team name for 2014 world cup final

console.log(finals2014[0]["Away Team Name"]);

//(c) Home Team goals for 2014 world cup final

console.log(finals2014[0]["Home Team Goals"]);

//(d) Away Team goals for 2014 world cup final

console.log(finals2014[0]["Away Team Goals"]);

//(e) Winner of 2014 world cup final */

console.log(finals2014[0]["Win conditions"]);

/* 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 2: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀
Use getFinals to do the following:
Expand All @@ -26,9 +40,15 @@ Use getFinals to do the following:
💡 HINT - you should be looking at the stage key inside of the objects
*/

function getFinals(/* code here */) {
/* code here */
function getFinals(data) {
let finalData = []
for (let i=0; i<data.length; i++){
if (data[i].Stage === 'Final'){
finalData.push(data[i])
}
}return finalData
}
console.log(getFinals(fifaData));



Expand All @@ -38,8 +58,9 @@ Use the higher-order function called getYears to do the following:
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 */
function getYears(data, getFinals) {
const years = getFinals(data)
return years.map(item => item.Year)
}


Expand All @@ -52,8 +73,11 @@ Use the higher-order function getWinners to do the following:
💡 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 */
function getWinners(data, getFinals) {
let finals = getFinals(data)
let winners = finals.map(teams => {
return teams['Home Team Goals'] > teams['Away Team Goals'] ? teams['Home Team Name'] : teams['Away Team Name'] });
return winners
}


Expand All @@ -69,8 +93,14 @@ Use the higher-order function getWinnersByYear to do the following:
💡 HINT: the strings returned need to exactly match the string in step 4.
*/

function getWinnersByYear(/* code here */) {
/* code here */
function getWinnersByYear(data, getFinals, getYears) {
const winnerYear = [];
const year = getYears(data, getFinals);
const country = getWinners(data, getFinals);
for (let x = 0; x < year.length; x++) {
winnerYear.push(`In ${year[x]}, ${country[x]} won the world cup!`)
}
return winnerYear
}


Expand All @@ -89,9 +119,17 @@ Use the higher order function `getAverageGoals` to do the following:

*/

function getAverageGoals(/* code here */) {
/* code here */
}
function getAverageGoals(data) {
let homeGoals = data.reduce((x, y) => {
return x += y["Home Team Goals"];
}, 0) / data.length;
let awayGoals = data.reduce((x, y) => {
return x += y["Away Team Goals"];
}, 0) / data.length;
return (homeGoals+awayGoals).toFixed(2);
};

console.log(getAverageGoals(fifaData));



Expand Down