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
66 changes: 56 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,40 @@ Practice accessing data by console.log-ing the following pieces of data note.

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

const fifa2014 = [{}]
fifaData.filter((element) => {
if(element.Year === 2014){
fifa2014.push(element)
}
})

//(a) Home Team name for 2014 world cup final
const HomeName2014 = []
fifa2014.forEach((element) => {
HomeName2014.push(element['Home Team Name'])
})


//(b) Away Team name for 2014 world cup final
const AwayName2014 = []
fifa2014.forEach((element) => {
AwayName2014.push(element['Away Team Name'])
})

//(c) Home Team goals for 2014 world cup final
const HomeGoal2014 = []
fifa2014.forEach((element) => {
HomeGoal2014.push(element['Home Team Goals'])
})

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

const AwayGoal2014 = []
fifa2014.forEach((element) => {
AwayGoal2014.push(element['Away Team Goals'])
})


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


Expand All @@ -26,8 +52,11 @@ 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(arr) {
const finals = arr.filter(function(item){
return item.Stage === 'Final';
})
return(finals)
}


Expand All @@ -38,8 +67,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(arr,cb) {
return cb(arr).map(item => item.Year);

}


Expand All @@ -52,8 +82,17 @@ 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(arr,cb) {
const winner = []
cb(arr).forEach((element) => {
if(element['Home Team Goals'] > element['Away Team Goals']){
winner.push(element['Home Team Name'])
}
else {
winner.push(element['Away Team Name'])
}
})
return(winner)
}


Expand All @@ -69,12 +108,16 @@ 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(arr,finalscb,yearscb,winnercb) {
const whoWon = winnercb(arr,finalscb)
const whatYear = yearscb(arr,finalscb)
return whoWon.map((element, index) => `In ${whatYear[index]}, ${element} won the world cup!` )

}




/* 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 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
Expand All @@ -89,8 +132,11 @@ Use the higher order function `getAverageGoals` to do the following:

*/

function getAverageGoals(/* code here */) {
/* code here */
function getAverageGoals(finalscb) {
const averageHomeGoals = finalscb.reduce(function(acc,element) {
return acc + element['Home Team Goals'] + element['Away Team Goals'];
}, 0)
return (averageHomeGoals / finalscb.length).toFixed(2);
}


Expand Down