let str = 'aaaadf'; function max(str){ let arr = str.split(''); return arr.reduce((obj,item)=>{ if(item in obj){ obj[item]++; if(obj[item]>obj["max"]){ obj["max"] = obj[item]; } }else{ obj[item]=1; } return obj; },{"max":0}).max } console.log(max(str))