March 16th, 2024
What's missing in this code?
function countMostFrequentLetters(string)
const letterCounts = {};
for (const char of string)
// check if char is alphabet
if (char.toLowerCase() !== char.
)
const lowerChar = char.toLowerCase();
letterCounts[lowerChar] += letterCounts[lowerChar] ?
: 0;
}
}
const maxCount = Math.max(...Object.values(letterCounts));
// print most popular letters
const mostPopularLetters = [];
for (const [key, value] of Object.
(letterCounts))
if (value === maxCount)
mostPopularLetters.push(
);
}
}
return mostPopularLetters;
}
console.log(countMostFrequentLetters('mango and oranges')); // ['a', 'n']
Type or select from these options