how to check consecutive characters in javascript

Solutions on MaxInterview for how to check consecutive characters in javascript by the best coders in the world

showing results for - "how to check consecutive characters in javascript"
Benjamin
21 Apr 2017
1var password = '5236aaa121';
2
3for(var i = 0; i< password.length; i++) {
4    var numberOfRepeats = CheckForRepeat(i, password, password.charAt(i));
5    //do something
6
7}
8
9function CheckForRepeat(startIndex, originalString, charToCheck) {
10    var repeatCount = 1;
11    for(var i = startIndex+1; i< password.length; i++) {
12        if(originalString.charAt(i) == charToCheck) {
13            repeatCount++;
14        } else {
15        return repeatCount;
16        }   
17    }
18    return repeatCount;
19}
20