const str = 'abcdacbdabcdabcdab'
let total = {}
for (let i = 0; i < str.length; i++) {
if (total[str[i]]) {
total[str[i]] += 1
} else {
total[str[i]] = 1
}
}
let max = 0
let key = []
for (const k in total) {
if (max < total[k]) {
max = total[k]
}
}
for (const k in total) {
if (total[k] === max) key.push(k)
}
console.log(`出现次数最多的是: ${key.join(' ')}出现了${max}次`) // 出现次数最多的是: a b出现了5次
其他两种方法