20200323
var arrNew = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']var oldString = "eeewwwwwoop"/*新字符串*/var oldString1 = ''/*老字符串的长度*/var stLength = oldString.length/*新字符串的长度*/var newLength = ""/*最多的字母*/var saveSt = ''/*NNN是字母个数,MMM是最多的个数*/var MMM = 0var NNN = 0for(let i = 0 ;i<arrNew.length;i++){ if(oldString.indexOf(arrNew[i])>-1){/*先用split将字符串拆成数组,然后再用join搞成字符串*/ oldString1=oldString.split(arrNew[i]).join("") newLength = oldString1.length NNN = stLength-newLength if(NNN>MMM){ MMM = NNN saveSt = arrNew[i] } }} 来源: