Medium
Your e-commerce platform needs to implement a flexible sorting system for products. The current code sorts products by price, but customers are complaining about inconsistent results. What's the correct way to modify the sort implementation?
1const products = [2 { name: "Laptop", price: 999.99, rating: 4.5, stock: 12 },3 { name: "Phone", price: 699.99, rating: 4.8, stock: 8 },4 { name: "Tablet", price: 499.50, rating: 4.2, stock: 0 },5 { name: "Smartwatch", price: 199.99, rating: 4.6, stock: 5 }6];78function sortProducts(items) {9 return items.sort((a, b) => {10 // Missing sorting logic11 });12}1314console.log(sortProducts(products));