let arr =[12,56,102,89,56,43,221]functionradixSort(arr){if(arr ===null|| arr.length <2){return}radix(arr,maxBits(arr))}functionradix(arr,num){let base =10let help =newArray(arr.length)for(let i =1; i <= num ;i++){let count =newArray(base).fill(0)for(let k =0; k < arr.length;k++){let n =getNum(arr[k],i)
count[n]+=1}for(let x =1;x < count.length;x++){
count[x]+= count[x-1]}for(let y = arr.length-1; y>=0; y--){let z =getNum(arr[y],i)
help[--count[z]]= arr[y]}for(let m =0; m < arr.length;m++){
arr[m]= help[m]}}}functionmaxBits(arr){let max = arr[0]for(let i =0; i < arr.length; i++){
max = arr[i]> max ? arr[i]: max
}let res =0while(max >0){
res +=1
max = Math.floor(max /10)}return res
}functiongetNum(num,d){let n = Math.floor(num / Math.pow(10,d-1))return n %10}radixSort(arr)
console.log(arr)