SOURCE

function countingSort (arr) {
  var conts = [];
  var result = [];
  var i = 0;
  for (var val of arr) {
    conts[val] = (conts[val] || 0) + 1;
  }
  while(i<conts.length){
    if(conts[i]!==undefined){
      for (let j = 0; j < conts[i]; j++) {
        result.push(i);
      }
    }
    i++;
  }
  return result;
}
console.log(countingSort([3,3,44,38,5,2,46,4,3]));
console 命令行工具 X clear

                    
>
console