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
36 changes: 23 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,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(array) {
const allFinals = array.filter(function(item){
return item.Stage === 'Final';
})
return allFinals;
}


// 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(array, getFinalsCB) {
return getFinalsCB(array).map(item => item.Year);

}


/* 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 4: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀
Expand All @@ -52,8 +54,9 @@ 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(array, getFinalsCB) {
return getFinalsCB(array).map(item => item['Home Team Goals'] > item['Away Team Goals'] ?
item ['Home Team Name'] : item ['Away Team Name']);
}


Expand All @@ -69,8 +72,12 @@ 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 winners = getWinnersCB(array, getFinals)
const years = getYearsCB(array, getFinals)


return winners.map((item, index) =>`In ${years[index]}, ${item} won the world cup!`);
}


Expand All @@ -88,8 +95,11 @@ Use the higher order function getAverageGoals to do the following:

*/

function getAverageGoals(/* code here */) {
/* code here */
function getAverageGoals(array) {
const avgHomeGoals = array.reduce(function(accumulator, item){
return accumulator + item['Home Team Goals'] + item ['Away Team Goals'];
}, 0)
return (avgHomeGoals / array.length).toFixed(2);
}


Expand Down