This article mainly introduces the JavaScript implementation of the number of occurrences of the most frequent characters and the number of occurrences, this article directly gives the implementation code, the need for friends can refer to the
"What is the most frequently occurring character in a string, and how many times has it occurred?" ”
See this demand, I think most people should first think of the conversion of the array, and then do the processing, of course, can solve the problem, and then provide a clever algorithm design, without an array, you can quickly solve the problem, 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);