Skip to content

Instantly share code, notes, and snippets.

@RachelSa
Created February 17, 2018 20:43
Show Gist options
  • Save RachelSa/a99f02e1b984d7c9209469ce0a352fda to your computer and use it in GitHub Desktop.
Save RachelSa/a99f02e1b984d7c9209469ce0a352fda to your computer and use it in GitHub Desktop.
Find the event with the highest score
let events = [
{title: "lowest scored event", score: "1.23"},
{title: "highest scored event", score: "4.05"},
{title: "middle scored event", score: "3.75"}
]
function maxScoredEvent(events){
return events.reduce((p,c) => {
return p.score > c.score ? p : c
})
}
console.log(maxScoredEvent(events))
// { title: 'highest scored event', score: '4.05' }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment