Product prices array is not giving me an expected result.
let productPrices = [10.33, 2.55, 1.06, 5.77];
console.log(productPrices.sort());
Result of above code:
(4) [1.06, 10.33, 2.55, 5.77]
Expecting:
(4) [1.06, 2.55, 5.77, 10.33]
Product prices array is not giving me an expected result.
let productPrices = [10.33, 2.55, 1.06, 5.77];
console.log(productPrices.sort());
Result of above code:
(4) [1.06, 10.33, 2.55, 5.77]
Expecting:
(4) [1.06, 2.55, 5.77, 10.33]
You also have to make a function for comparing.
let productPrices = [10.33, 2.55, 1.06, 5.77];
console.log(productPrices.sort((a,b)=>a-b));