sorting basic

PHOTO EMBED

Wed Apr 12 2023 05:58:05 GMT+0000 (Coordinated Universal Time)

Saved by @davidmchale #function #return #values #filtering

const prices = [400.50, 3000, 99.99, 35.99, 12.00, 9500];


// Sorting books by their rating: // use slice to copy the array
const acscendingsOrders = prices.slice().sort((a, b) => a.toFixed(2) - b.toFixed(2))
const descendingOrders = prices.slice().sort((a, b) => b.toFixed(2) - a.toFixed(2))

content_copyCOPY

usiing slice() with sort() will copy the array otherwise it will modify the original array