let a = "aaaaaaaaadsdfdfdfeeeeeeee";
let json = {}
for(let i=0;i<a.length;i++){
if(!json[a[i]]){
json[a[i]] =1
}else{
json[a[i]]++
}
}
console.log(json)
let maxNum = 0
let maxStr;
for(let i in json){
if(json[i]>maxNum){
maxNum = json[i]
maxStr = i
}
}
console.log("出现次数最多的字符是"+maxStr+",出现了"+maxNum+"次")
原文地址:https://blog.51cto.com/13550695/2462774
时间: 2024-10-19 10:57:43