JenMorgan / js-learning

0 stars 0 forks source link

Сортировка массива #51

Open JenMorgan opened 4 years ago

JenMorgan commented 4 years ago
let arr = [5, 20, -1, -10, 8];

function compare (a, b) { 
    if (a < b) return 1;
    if (a == b) return 0;
    if (a > b) return -1;
}

function sortArr (arr) {
    arr.sort(compare);
}

sortArr(arr);

alert(arr);