The Full Counting Sort

  • + 0 comments

    -- JavaScript --

    function countSort(arr) {
      // Write your code here
      const obj = {};
      const mid = arr.length / 2;
      arr.forEach((e, i) => {
        if (i < mid) {
          if (obj[e[0]]) obj[e[0]].push('-');
          else obj[e[0]] = ['-']
          return
        }
        if (obj[e[0]]) obj[e[0]].push(e[1])
        else obj[e[0]] = [e[1]]
      })
    
      console.log(Object.values(obj).map((e) => e.join(' ')).join(' '));
    }