📜  如何检查javascript代码示例中的连续字符

📅  最后修改于: 2022-03-11 15:01:58.430000             🧑  作者: Mango

代码示例1
var password = '5236aaa121';

for(var i = 0; i< password.length; i++) {
    var numberOfRepeats = CheckForRepeat(i, password, password.charAt(i));
    //do something

}

function CheckForRepeat(startIndex, originalString, charToCheck) {
    var repeatCount = 1;
    for(var i = startIndex+1; i< password.length; i++) {
        if(originalString.charAt(i) == charToCheck) {
            repeatCount++;
        } else {
        return repeatCount;
        }   
    }
    return repeatCount;
}