Count repeated letters in a string

前端 未结 7 1980
耶瑟儿~
耶瑟儿~ 2021-01-06 02:06

I\'m stuck with the following problem: I need to find repeated characters in a string. Basically what I want is regular expression that will match like that



        
7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-06 02:18

    function charCount(str){
        let arr = str.split('');
        return arr.reduce((a,p)=>{
            a[p] = a[p] ? (a[p]+1) : 1;
            return a;
        },{});
    };
    

提交回复
热议问题