3.英文文章出现次数最多的单词

406 阅读1分钟

英文文章出现次数最多的单词

给定一篇英文文章,找出英文文章出现次数最多的单词

           function counts(article){
            article = article.trim().toUpperCase();
            console.log(article);
            var array = article.match(/[A-z]+/g);
            console.log(array);
            article = " "+array.join("  ")+" ";
            console.log(article);
            var max = 0,word,num = 0,maxword="";
            for(var i = 0; i < array.length; i++) {        
                word = new RegExp(" "+array[i]+" ",'g');
                num = article.match(word).length;
                if(num>max){
                    max=num;
                    maxword = array[i];
                }
            }
            console.log(maxword+" "+max);
        }       
counts("Age has reached the end of the beginning of a word. May be guilty.in his seems.to passing a lot of different life became the appearance of the same day;");