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 );