-1

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]

1 Answers1

1

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));
ellipsis
  • 12,049
  • 2
  • 17
  • 33