Skip to content

Instantly share code, notes, and snippets.

@timgarciaa
Created July 2, 2022 14:15
Show Gist options
  • Save timgarciaa/5a3c7748abfe49a6c22488811ff9494b to your computer and use it in GitHub Desktop.
Save timgarciaa/5a3c7748abfe49a6c22488811ff9494b to your computer and use it in GitHub Desktop.
Using reduce to find the highest price drink
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