Created
July 2, 2022 14:15
-
-
Save timgarciaa/5a3c7748abfe49a6c22488811ff9494b to your computer and use it in GitHub Desktop.
Using reduce to find the highest price drink
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
const drinks = [ | |
{name: 'coffee', price: 1.99}, | |
{name: 'tea', price: 1.75}, | |
{name: 'milk', price: 1.5}, | |
] | |
const highestPricedDrink = drinks.reduce((highestPriced, drink) => { | |
return highestPriced.price > drink.price ? highestPriced: drink; | |
}, {}); | |
console.log(highestPricedDrink); | |
// { name: 'coffee', price: 1.99 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment