You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
function maxChar(str) {
const charMap = {};
let max = 0;
let maxChar = '';
for(let element of str) {
charMap[element] = charMap[element] ? charMap[element] + 1 : 1;
if(charMap[element] > max) {
max = charMap[element];
maxChar = element
}
}
return maxChar;
}
instead of
function maxChar(str) {
const charMap = {};
let max = 0;
let maxChar = '';
for (let char of str) {
if (charMap[char]) {
charMap[char]++;
} else {
charMap[char] = 1;
}
}
for (let char in charMap) {
if (charMap[char] > max) {
max = charMap[char];
maxChar = char;
}
}
return maxChar;
}
The text was updated successfully, but these errors were encountered:
The solution should not avoid the second loop?
instead of
The text was updated successfully, but these errors were encountered: