program to sort an arrray javascript code example
Example: js sort an array
// sort an array
// by drinks: lowest to highest
function sortDrinkByPrice(drinks) {
return drinks.sort((a, b) => {
return a.price - b.price;
});
}
// parse the array as parameters within the function
console.log(sortDrinkByPrice([{name: "lemonade", price: 50},{name: "lime", price: 10}]));