js统计字符串出现次数最多的字母

    var test = 'asdfasgakjwihfhfbak';
    var test_dict = {};
    var max = 0;
    var max_str = '';
    test = test.toLocaleLowerCase();
    for(let test1=0;test1<test.length;test1++){
        key = test[test1];
        if(test_dict[key]){
            test_dict[key]++;
        }else{
            test_dict[key]=1;
        }
    }
    for(let test2 in test_dict){
        if(test_dict[key]>max){
            max = test_dict[test2];
            max_str = test2;
        }
    }
    console.log(max_str);

你可能感兴趣的:(js)