Created
February 17, 2018 20:43
-
-
Save RachelSa/a99f02e1b984d7c9209469ce0a352fda to your computer and use it in GitHub Desktop.
Find the event with the highest score
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
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