How to make a function which return the object that has the lowest cost.
sandwitch = [
{
'type':"Italian",
'cost':7.69 ,
'isVageterian':false
},
{
'type':"Veggie",
'cost':5.50 ,
'isVageterian':true
},
{
'type':"Jackfruit",
'cost':8.50 ,
'isVageterian':true
},
]
sandwitch = [{
'type': "Italian",
'cost': 7.69,
'isVageterian': false
},
{
'type': "Veggie",
'cost': 5.50,
'isVageterian': true
},
{
'type': "Jackfruit",
'cost': 8.50,
'isVageterian': true
},
]
const lowest = sandwitch.reduce(
(prev, curr) =>
prev.cost < curr.cost ?
prev :
curr
)
alert(lowest.cost);