The Full Counting Sort

  • + 0 comments

    Typescript

    function countSort(arr: string[][]): void {
      const arrHalfLen = Math.ceil(arr.length / 2);
      let result = [];
      const _arr = [];
    
      for (let i = 0; i < arr.length; i++) {
        if (i < arrHalfLen) {
          _arr.push([arr[i][0], '-']);
          continue;
        }
        _arr.push([arr[i][0], arr[i][1]]);
      }
    
      _arr.sort((a: any, b: any) => a[0] - b[0]);
    
      for (let i = 0; i < _arr.length; i++) {
        result.push(_arr[i][1]);
      }
    
      console.log(result.join(' '));
    }