We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
统计给定字符串中出现次数最多的字符
要求:输出字符串中出现次数最多的字符和出现的次数
例如:
传入字符串 "aabbbgggg"
输出
{ str: "g", num: 4 }
let maxStr = (str) => { let obj = {} for (let i in str) { let char = str[i] obj[char] = obj.hasOwnProperty(char) ? obj[char] + 1 : 1 } let char = '' let num = 0 for (let key in obj) { if (obj[key] > num) { char = key num = obj[key] } } return { str: char, num: num } }
执行结果:
maxStr('aabbbgggg') // 调用 // 输出 { str: 'g', num: 4 }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
题目
统计给定字符串中出现次数最多的字符
要求:输出字符串中出现次数最多的字符和出现的次数
例如:
传入字符串 "aabbbgggg"
输出
解析
答案
执行结果:
The text was updated successfully, but these errors were encountered: