Skip to content
Open
Show file tree
Hide file tree
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
76 changes: 57 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,30 @@ const { fifaData } = require('./fifa.js')

/* 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 1: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀
Practice accessing data by console.log-ing the following pieces of data note, you may want to filter the data first 😉*/
const finals2014 = fifaData.filter(function(item){
return item.Year === 2014 && item.Stage=== 'Final'
});

//(a) Home Team name for 2014 world cup final
// console.log(finals2014);
// //(a) Home Team name for 2014 world cup final

//(b) Away Team name for 2014 world cup final
// console.log(finals2014[0]["Home Team Name"]);

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

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

//(e) Winner of 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 @@ -24,9 +37,12 @@ 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(array) {
let finals = fifaData.filter(function(item){
return item.Stage === 'Final'; //this belongs to filter
});
return finals;}
// this return belongs to getFi



Expand All @@ -36,9 +52,14 @@ Use the higher-order function called getYears to do the following:
2. Receive a callback function getFinals from task 2
3. Return an array called years containing all of the years in the getFinals data set*/

function getYears(/* code here */) {
/* code here */
function getYears(array, cb) {
const years = cb(array).map(function(item){
return item.Year;
});
return years;
}
console.log('task 3', getYears(fifaData, getFinals));




Expand All @@ -49,11 +70,22 @@ Use the higher-order function getWinners to do the following:
3. Determines the winner (home or away) of each `finals` game.
4. Returns the names of all winning countries in an array called `winners` */

function getWinners(/* code here */) {
/* code here */
function getWinners(array, callback) {
const winners = callback(array).map(function(item){
if(item['Home Team Goals'] > item['Away Team Goals']){
return item['Home Team Name'];
}
else {
return item['Away Team Name'];
}

});
return winners;
}


console.log('task 4', getWinners(fifaData, getFinals));


/* 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 5: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀
Use the higher-order function getWinnersByYear to do the following:
Expand All @@ -66,11 +98,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(array, getFinalscb, getYearscb, getWinnerscb) {
const finals = getFinalscb(array, getFinals);
const winners = getWinnerscb(array, getFinals);
const years = getYearscb(array, getFinals);
return winners.map((item, index) => `In ${years[index]}, ${item} won the world cup!`
)}

console.log(getWinnersByYear(fifaData, getFinals, getYears, getWinners));

/* 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 6: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀
Use the higher order function getAverageGoals to do the following:
Expand All @@ -82,11 +117,14 @@ Use the higher order function getAverageGoals to do the following:
Example of invocation: getAverageGoals(getFinals(fifaData));
*/

function getAverageGoals(/* code here */) {
/* code here */
function getAverageGoals(getFinalscb) {
const totalGoals = getFinalscb.reduce(function(accu, currentGame){
return accu + currentGame["Home Team Goals"] + currentGame["away Team Goals"];
}, 0)
return(totalGoals / getFinalscb.length).toFixed(2);
}


console.log(getAverageGoals(getFinals(fifaData)));


/// 🥅 STRETCH 🥅 ///
Expand Down
Loading