下記のアルゴリズムを実装しましょう。
counting sort
// COUNTING SORT ALGORITHM
function countingSort(arr) {
    // find the maximum value in the array
    let max = Math.max(...arr);

    // create an array to store the count
    let countArray = new Array(max+1).fill(0);

    // store the count of each element in countArray
    for (let i=0; i<arr.length; i++) {
        countArray[arr[i]]++;
    }

    // calculate the cummulative sum of the elements
    for (let i=1; i<countArray.length; i++) {
        countArray[i] += countArray[i-1];
    }

    // create an output array
    let output = new Array(arr.length).fill(0);

    // find the index for each element in the original array and add to output array
    for (let i=arr.length-1; i>=0; i--) {
        output[countArray[arr[i]]-1] = arr[i];
        countArray[arr[i]]--;
    }

    // copy the sort result back to the original array
    for (let i=0; i<output.length; i++) {
        arr[i] = output[i];
    }
}