SOURCE

// 计数排序
function countingSort(nums) {
    let arr = [];
    let max = Math.max(...nums);
    let min = Math.min(...nums);
    // 装桶
    for (let i = 0, len = nums.length; i < len; i++) {
        let temp = nums[i];
        arr[temp] = arr[temp] + 1 || 1;
        console.log(`装桶键为${temp}-值为${arr[temp]}----------`, arr);
    }
    let index = 0;
    // 还原原数组
    for (let i = min; i <= max; i++) {
        while (arr[i] > 0) {
            nums[index++] = i;
            arr[i]--;
        }
    }
    return nums;
}

console.log(countingSort([9, 0, 8, 9, 89, 76, 87, 67, 90]));
console 命令行工具 X clear

                    
>
console