feat(mostUsedChar): Implementacao da funcao mostUsedChar()

This commit is contained in:
Wellington Duarte Santos 2022-11-01 09:31:47 -03:00
parent 0efd909b9c
commit 8300a31ec7

View File

@ -1,4 +1,24 @@
export function mostUsedChar(text) { export function mostUsedChar(text) {
// implementar logica aqui text.toLowerCase();
return ""
let sorted = text.split('').sort().join('');
let cont = 1;
let repeatedTimes = 0;
let mostUsed = "";
for(let i = 0; i < sorted.length; i++){
if(sorted[i] === sorted[i + 1]){
cont++;
}
else{
if(cont > repeatedTimes){
repeatedTimes = cont;
mostUsed = sorted[i];
}
cont = 1;
}
}
return mostUsed;
} }