Last active
January 26, 2016 07:33
-
-
Save MikeDigitize/d5faea6ad87c09c38ee1 to your computer and use it in GitHub Desktop.
Some coding challenges for the AO front end team who are learning JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// take a bunch of football results from this object | |
// and return an array of results summaries including teams competing, score and scorers | |
var results = { | |
"02-01-2016" : { | |
results : [{ | |
teamA : { | |
name : "Manchester United", | |
goals : 2, | |
scorers : ["Rooney", "Martial"], | |
booked : ["Rooney", "DeGea", "Carrick"], | |
sentOff : [], | |
subs : [{ name : "Memphis", replaced : "Rooney", time : 82 }] | |
}, | |
teamB : { | |
name : "Watford", | |
goals : 0, | |
scorers : [], | |
booked : ["Ekstrand", "Deeney"], | |
sentOff : [ { name : "Deeney", time : 57 }], | |
subs : [ | |
{ name : "Johnson", replaced : "Britos", time : 58 }, | |
{ name : "Watson", replaced : "Behrami", time : 58 } | |
] | |
} | |
}, { | |
teamA : { | |
name : "Liverpool", | |
goals : 1, | |
scorers : ["Sturridge"], | |
booked : ["Allen"], | |
sentOff : [], | |
subs : [{ name : "Benteke", replaced : "Sturridge", time : 65 }] | |
}, | |
teamB : { | |
name : "Chelsea", | |
goals : 1, | |
scorers : ["Costa", "Costa"], | |
booked : ["Terry", "Costa", "Mikel"], | |
sentOff : [ { name : "Costa", time : 67 }], | |
subs : [{ name : "Mikel", replaced : "Willian", time : 71 }] | |
} | |
}] | |
}, | |
"03-01-2016" : { | |
results : [{ | |
teamA : { | |
name : "Manchester City", | |
goals : 3, | |
scorers : ["Aguero", "Aguero", "Aguero"], | |
booked : ["Hart"], | |
sentOff : [], | |
subs : [{ name : "Bony", replaced : "Aguero", time : 70 }] | |
}, | |
teamB : { | |
name : "Newcastle", | |
goals : 0, | |
scorers : [], | |
booked : ["Collocini", "Cisse", "Perez"], | |
sentOff : [ | |
{ name : "Collocini", time : 34 }, | |
{ name : "Krul", time : 55 } | |
], | |
subs : [{ name : "Elliot", replaced : "Sissoko", time : 34 }] | |
} | |
}, { | |
teamA : { | |
name : "Leicester", | |
goals : 1, | |
scorers : ["Vardy"], | |
booked : [], | |
sentOff : [], | |
subs : [{ name : "Marrez", replaced : "Ulloa", time : 56 }] | |
}, | |
teamB : { | |
name : "Arsenal", | |
goals : 0, | |
scorers : [], | |
booked : ["Cech"], | |
sentOff : [], | |
subs : [ | |
{ name : "Ramsey", replaced : "Ozil", time : 71 }, | |
{ name : "Sanchez", replaced : "Giroud", time : 71 } | |
] | |
} | |
}] | |
} | |
}; | |
function getResults(_results) { | |
return Object.keys(_results) | |
.map(key => _results[key].results) | |
.reduce((arr, i) => arr.concat(i), []) | |
.map(item => { return { | |
game : `${item.teamA.name} vs. ${item.teamB.name}`, | |
score : `${item.teamA.goals}-${item.teamB.goals}`, | |
scorers : item.teamA.scorers.concat(item.teamB.scorers) | |
}}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment