SOURCE

var str = '22222222222222222abbccccdddddeeeeeerrrrrrrrgggggggggg44444444444444'
console.log(str.length)
let c = 0
function getMaxLength(str) {
    const strLength = str.length
    const result = {
        code: '',
        count: 0
    }
    let j = strLength - 1
    let isFinish = false
    for (let i = 0; i < strLength; i++) {
        let count = 0
        for (let j = i; j < strLength; j++) {
            c += 1
            if (str[i] === str[j]) {
                count++
            }
            if (str[i] !== str[j] || j === strLength - 1) {
                if (count > result.count) {
                    result.code = str[i]
                    result.count = count
                    count = 0
                }

                if (i < strLength - 1) {
                    i = j - 1
                } else {
                    isFinish = true
                }
                break
            }

        }
        console.log(isFinish)
    }

    return result
}
const res = getMaxLength(str)

console.log('c------------->', c)
console.log(res)
console 命令行工具 X clear

                    
>
console