我先回答一个
- var str = "adadfdfseffserfefsefseeffffftsdg"; //命名一个变量放置给出的字符串
- var result = {};
- var max = 0;
- var maxChar = '';
- for ( var i = 0; i < str.length; i++) {
- var c = str.charAt(i);
- if (result[c]) {
- result[c]++;
- if(result[c] > max){
- max = result[c];
- maxChar = c;
- }
- } else {
- result[c] = 1;
- }
- }
- alert(max + ':' +maxChar)