Open ForeveHG opened 3 years ago
function findMaxCountStr(str) { let chartOfCount = {}; while(str) { let chart = str.substr(0,1); if(chartOfCount[chart]) { chartOfCount[chart]++; } else { chartOfCount[chart] = 1; } str = str.substr(1) } return Object.keys(chartOfCount).map(chart => { return { chart: chart, count: chartOfCount[chart] } }).sort((a,b) => b.count - a.count)[0] } //测试 findMaxCountStr("aaaaaabbccccccccccc") // {chart: "c", count: 11}