日期:2014-05-16 浏览次数:20435 次
function(str){ var maxLength = 0; //最大字符串长度 var res = {}; //每种字符出现次数 while(str){ //while循环效率高于for循环 var oldStr = str; var getStr = str.substr(0,1); //取第一个字符 str = str.replace(new RegExp(getStr,"g"),""); //oldStr.length - str.length; //取得重复字符串个数 //res[getStr] = oldStr.length - str.length;//字符出现次数 if(oldStr.length - str.length > maxLength ) { maxLength = oldStr.length-str.length; //最大字符串长度 } } return res; }