JS查找英文文章中出现频率最高的单词

编程学习 2021-07-04 18:31www.dzhlxh.cn编程入门
这篇文章主要为大家详细介绍了JS查找英文文章中出现频率最高的单词,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

狼蚁网站SEO优化这个函数是js查找一篇英文文章中出现频率最高的单词(由26个英文字母大小写构成),输出该单词及出现次数,不区分大小写,主要是正则的运用:

function counts(article){
 article = article.trim().toUpperCase();
 var array = article.match(/[A-z]+/g);
 article = " "+array.join(" ")+" ";
 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;");

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持狼蚁SEO。

Copyright © 2016-2025 www.dzhlxh.cn 金源码 版权所有 Power by

网站模板下载|网络推广|微博营销|seo优化|视频营销|网络营销|微信营销|网站建设|织梦模板|小程序模板