Desafio 9 Feito

This commit is contained in:
matheusjardimgarcia 2022-11-02 10:54:53 -03:00
parent dc3cfbeb10
commit cb1011783f

View File

@ -1,4 +1,34 @@
export function mostUsedChar(text) { export function mostUsedChar(str) {
// implementar logica aqui const charMap = {};
return "" let max = 0;
} let mostUsedChar = '';
// create character map
for (let char of str) {
if (charMap[char]) {
// increment the character's value if the character existed in the map
charMap[char]++;
} else {
// Otherwise, the value of the character will be increamented by 1
charMap[char] = 1;
}
}
// find the most commonly used character
for (let char in charMap) {
if (charMap[char] > max) {
max = charMap[char];
mostUsedChar = char;
}
}
return mostUsedChar;
}
console.log(mostUsedChar("fdgdfgff"));
console.log(mostUsedChar("Lorem ipsum"));
console.log(mostUsedChar("adsassdasd"));
console.log(mostUsedChar("testeeeee"));