function radixSort(array){
    var max = Math.max.apply(0, array);
    var m = getLoopTimes(max), len = array.length;
    var buckets = [];
    for(let i = 0; i < 10; i++){
        buckets[i] = []; //初始化10个桶
    }
    for(var d = 1; d <= m; d++){//个位，十位，百位，千位这样循环
        radixSortImpl(array, buckets, len, d);
    }
    return array;
}
// 根据数字某个位数上的值得到桶的编号
function getBucketNumer(num, d){
    return (num+"").reverse()[d];
}
//或者这个 
function getBucketNumer(num,i){
    return Math.floor((num / Math.pow(10, i)) % 10);
}
//获取数字的位数
function getLoopTimes(num){
    var digits = 0;
    do{
        if(num>1){
            digits++;
        }else{
            break;
        }
    }while((num = num /10));
    return digits;
}
function radixSortImpl(array, buckets, len, d){
    //入桶
    for(let i = 0; i < len; i++){
        let el = array[i];
        let index = getBucketNumer(el, d);
        buckets[index].push(el);
    }
    var k = 0;
    //重写原桶
    for(let i = 0; i < 10; i++){
        let bucket = buckets[i];
        for(let j = 0; j < bucket.length; j++){
            array[k++] = bucket[j];
        }
        bucket.length = 0;
    }
}
// test
var arr = [278,109,63,930,589,184,505,269,8,83];
console.log(radixSort(arr));