The Full Counting Sort

  • + 0 comments

    My answer in Typescript, noted

    function countSort(arr: string[][]): void {
        // create converted arr, fill with []
        let arr_converted = Array.from({ length: arr.length }, () => []);
    
        // forech element in [arr], add to [arr_converted]
        for (let i = 0; i < arr.length; i++) {
            let n = Number(arr[i][0])
            let c = i + 1 <= arr.length / 2 ? '-' : arr[i][1]
    
            arr_converted[n].push(c)
        }
    
        // print
        console.log(arr_converted.flat().join(' ').trim())
    }