const str = 'ababa'
let max = 0
let maxName
function mostNum(str) {
for (let i = 0; i < str.length; i++) {
let count = 1
for (let j = i + 1; j < str.length; j++) {
if (str[i] === str[j]) {
count++
if (count > max) {
max = count
maxName = str[j]
}
}
}
}
return {
max, maxName
}
}
console.log(mostNum(str));
找出字符串中出现次数最多的
最新推荐文章于 2024-06-14 15:02:13 发布