Solución
solution.tsTypeScript
export function mostFrequentChar(text: string): string {
const chars = text.split('');
const charsObj = {};
let currentLetter = text.at(0)
let currentFreq = -1;
for(const letter of chars) {
if ( charsObj[letter]) {
charsObj[letter]++
continue;
}
charsObj[letter] = 1;
}
Object.keys(charsObj).forEach(key => {
if ( charsObj[key] > currentFreq ) {
currentLetter = key;
currentFreq = charsObj[key]
}
})
return currentLetter;
}0respuestas