求字符串出现次数和最大值

var str = ‘abdgcjkssahajdfmmfd‘;

var aObj = {};

var num;

var strMax;

for (var i = 0; i < str.length; i++){

  var item = str.charAt(i);

  if(aObj[item]){

    aObj[item]++;

  }else{
    aObj[item] = 1;

  }

num = 1;

for(var key in aObj){

  if(num < aObj[key]){

    num = aObj[key];

    strMax = key;

  }

console。log(strMax, num);

 

posted @ 2020-03-16 11:20  花木兰r  阅读(163)  评论(0编辑  收藏  举报