SOURCE

let str = "aabbcc";

function getHighestFreqChar(s) {
    let resObj = {};
    let resArr = [];
    let max = 0;
    for (let i = 0, length = s.length; i < length; i++) {
        let word = s.charAt(i);
        if (resObj[word]) {
            resObj[word]++;
        } else {
            resObj[word] = 1;
        }
    }
    for (let key in resObj) {
        if (max < resObj[key]) {
            max = resObj[key];
        }
    }
    for (let key in resObj) {
        if (resObj[key] == max) {
            resArr.push(key);
        }
    }
    if (resArr.length > 1) {
        return resArr[1];
    }else{
        return resArr[0];
    }
}

console.log(getHighestFreqChar(str));
console 命令行工具 X clear

                    
>
console