michaelp0730
11/7/2019 - 5:06 AM

Sort numbers array

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;
});