Sort numeric arrays in JS either in ascending or descending order
const arr = [3, 5, 1, 2, 7, 6, 9]; const sortAsc = arr.sort(function (a, b) { return a - b; }); const sortDesc = arr.sort(function (a, b) { return b - a; });