// [2,1,6,3,3,4]=>[1,3,4,6,3,2] let string="helloworldddddddddd" function demo(string){ let arr=string.split(""); let newArr=arr.sort() let temp=0; let who; let index=0; for(let i=0;i<newArr.length;i++){ if(arr[i]==arr[i+1]){ index++; } if(arr[i]!==arr[i+1]){ if(temp<index){ temp=index+1; who=arr[i]; } else{ temp=temp; } index=0; } } console.log(who,temp) } console.log(demo(string))