Counting Sort 2

  • + 0 comments

    My answer in Typescript, just few changes

    function countingSort(arr: number[]): number[] {
        let arr_count = Array(100).fill(0)
    
        for (let i = 0; i < arr.length; i++) arr_count[arr[i]]++
    
        return arr_count.reduce((p, c, i) => [...p, ...Array(c).fill(i)], [])
    }