How to determine if a string contains a sequence of repeated letters

前端 未结 7 1927
没有蜡笔的小新
没有蜡笔的小新 2021-01-17 16:01

Using JavaScript, I need to check if a given string contains a sequence of repeated letters, like this:

\"aaaaa\"

How can I do t

7条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-17 16:08

    var char = "abcbdf..,,ffffd,,,d,,,";
    var tempArry={};
    
    for (var i=0; i < char.length; i++) {
        if (tempArry[char[i]]) {
            tempArry[char[i]].push(char[i]);
        } else {
            tempArry[char[i]] = [];
            tempArry[char[i]].push(char[i]);
        }
    }
    
    console.log(tempArry);
    

    This will even return the number of repeated characters also.

提交回复
热议问题