const str = 'yekmaakkccekymbvb';
const fn = str => {
const map = new Map();
for (let i = 0; i < str.length; i++) {
if (!map.has(str[i])) map.set(str[i], 1);
else if (map.has(str[i])) {
map.set(str[i], map.get(str[i]) + 1);
}
}
let max = 0;
let temp;
map.forEach((value, key) => {
if (value > max) {
max = value;
temp = key;
}
});
console.log(`${temp}是最多的字符,一共重复了${max}次`);
};
fn(str);
用map的理由只有一个,那就是快