var str = 'aaaadddsssssd'
function Statistics(str) {
var obj = {}
for (var i = 0; i < str.length; i++) {
obj.hasOwnProperty(str[i])?obj[str[i]]++:obj[str[i]] = 1
}
var strindex = 1, str2 = '', attr2 = []
for (var attr in obj) {
if (obj[attr] > strindex) {//如果没并列的
strindex = obj[attr]
str2 = attr
}
}
for (var attr in obj) {//处理并列第一
if (obj[attr] == strindex ) {
strindex = obj[attr]
attr2.push([attr])
}
}
return attr2.length == 1? `${str2}出现${strindex}次 `:`有并列${attr2}都出现${strindex}次`
}
console.log(Statistics(str))
console