This article describes how to use JavaScript to calculate the most frequently occurring characters and the number of occurrences of strings. This article provides the implementation code, for more information, see "calculate the maximum number of characters that appear in a string. How many times are there?"
Seeing this demand, I think most people should first think of converting it into an array and then processing it. Of course, it can solve the problem. Then here we provide a clever algorithm design without the need to convert the array, the Code is as follows:
The Code is as follows:
Var str = "adadfdfseffserfefsefseeffffftsdg ";
Var maxLength = 0;
Var result = "";
While (str! = ''){
OldStr = str;
GetStr = str. charAt (0 );
Str = str. replace (new RegExp (getStr, "g "),"");
If (oldStr. length-str.length> maxLength ){
MaxLength = oldStr. length-str.length;
Result = getStr + "=" + maxLength;
}
}
Alert (result );