<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>出现次数最多的字母</title>
</head>
<body>
<script>
var str = 'aaasdsdsddddccccyyyy'
function get(str){
const arr = str.split('')
return arr.reduce(function(pre,cur){
console.log(pre,cur);
if(cur in pre){
pre[cur]++
}else{
pre[cur] = 1
}
return pre
},{})
}
console.log(get(str));
var maxObj = get(str)
var maxStr = null
var max = 0
for(var key in maxObj){
if(max < maxObj[key]){
max = maxObj[key]
maxStr = key
}
}
console.log(`出现次数最多的字母是${maxStr},出现次数${max}`);
</script>
</body>
</html>