Merge pull request 'feat(mostUsedChar): algoritmo criado.' (#9) from feature/algorithm09 into development

Reviewed-on: #9
This commit is contained in:
Luiz Felipe Silva 2022-11-01 02:57:59 +00:00
commit e155699ab6

View File

@ -1,4 +1,21 @@
export function mostUsedChar(text) { export function mostUsedChar(text) {
// implementar logica aqui // implementar logica aqui
return "" let array = [];
let stringText = text.toLowerCase();
let letrasJuntas = stringText.replace(/ /g, '');
for(let i = 0; i < letrasJuntas.length; i++) {
let letra = letrasJuntas.charAt(i);
if(array[letra] != undefined) array[letra]++
else array[letra] = 1;
}
let letrasOrdenadas = Object.keys(array).sort(function order(key1, key2) {
if(array[key1] > array[key2]) return -1;
else if(array[key1] < array[key2]) return +1;
else return 0;
})[0];
return letrasOrdenadas;
} }