Skip to content
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
69 changes: 50 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@


const { fifaData } = require('./fifa.js')

// ⚽️ M V P ⚽️ //
Expand All @@ -7,15 +9,29 @@ 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
var filterMatch
for (var i = 0; i < fifaData.length; i++) {
if (fifaData[i].Year === 2014 && fifaData[i].Stage == "Final") {
filterMatch = fifaData[i]
}
}

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

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

var result = fifaData.filter(match => match["Year"] === 2014 && match["Stage"] === "Final")[0];
//(a) Home Team name for 2014 world cup final
//(b) Away Team name for 2014 world cup final
console.log(result['Away Team Name']);
//(c) Home Team goals for 2014 world cup final
console.log(result['Home Team Goals']);
//(d) Away Team goals for 2014 world cup final

console.log(result['Away Team Goals']);
//(e) Winner of 2014 world cup final */
if (result['Home Team Goals'] > result['Away Team Goals']) {
console.log(result['Home Team Name']);
} else {
console.log(result['Away Team Name']);
}


/* 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 2: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀
Expand All @@ -26,22 +42,24 @@ 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) {
return data.filter(match => match['Stage'] === 'Final');
}

console.log(getFinals(fifaData))

/* 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 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 */
function getYears(data, finals) {
var finalsList = finals(data);
return finalsList.map(match => match['Year']);
}

console.log(getYears(fifaData,getFinals))


/* 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 4: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀
Expand All @@ -52,10 +70,13 @@ 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,finals) {
var finalsList = finals(data);
return finalsList.map(match => (match['Home Team Goals'] > match['Away Team Goals']) ? match['Home Team Name'] : match['Away Team Name']);
}

console.log(getWinners(fifaData,getFinals))



/* 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 5: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀
Expand All @@ -69,11 +90,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,finals,years,winners) {
var winners = winners(data,finals)
var theYears = years(data,finals)
return winners.map((x,i) => `In ${theYears[i]}, ${x} won the world cup!`);
}

getWinnersByYear(fifaData,getFinals,getYears,getWinners)

/* 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 6: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀
Use the higher order function getAverageGoals to do the following:
Expand All @@ -88,10 +112,17 @@ Use the higher order function getAverageGoals to do the following:

*/

function getAverageGoals(/* code here */) {
/* code here */
}

function getAverageGoals(data) {
var homeGoals = data.reduce((x, y) => {
return x += y["Home Team Goals"];
}, 0) / data.length;
var 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