SOURCE

// 找出连续出现最多的字符和个数
// 'abcaakjbb' => { 'a': 2, 'b': 2 }
// 'abbkejsbcccwqaa' => { 'c': 3 }

const fn2 = (str) => {
    let i = 0
    let res = {}
    for(let j = 1; j < str.length; j++){
        if(str.charAt(i) === str.charAt(j)){
            let strRes = str.slice(i, j + 1)
            if(strRes.length > (Object.values(res)[0] || 0)){
                res = {}
                res[strRes.charAt(0)] = strRes.length
            }
            if(strRes.length === Object.values(res)[0]){
                res[strRes.charAt(0)] = strRes.length
            }
        } else {
            i = j
        }
    }
    console.log(res)
}
fn2('abbkejsbcccwqaaa')
console 命令行工具 X clear

                    
>
console