Return the first word with the greatest number of repeated letters

前端 未结 5 1163
慢半拍i
慢半拍i 2021-01-16 23:16

This is a question from coderbyte’s easy set. Many people asked about it already, but I’m really curious about what’s wrong with my particular solution (I know it’s a pretty

5条回答
  •  孤街浪徒
    2021-01-16 23:50

    I recommend use regular expression: /a+/g to find a list of letter with a key word a.

    My example :

    var str = aa yyyyy bb cccc cc dd bbb;
    

    Fist, find a list of different word :

    >>> ["a", "y", "b", "c", "d"]
    

    Use regular expression for each word in list of different word :

    var word = lstDiffWord[1];
                 var
    wordcount = str.match(new RegExp(word+'+','g')); 
    console.log(wordcount);
    
    >>>>["yyyyy"]
    

    Here is full example: http://jsfiddle.net/sxro0sLq/4/

提交回复
热议问题