forked from M3-Academy/challenge-algorithms-v2.0
feat(mostUsedChar): Implementacao da funcao mostUsedChar()
This commit is contained in:
parent
0efd909b9c
commit
8300a31ec7
@ -1,4 +1,24 @@
|
||||
export function mostUsedChar(text) {
|
||||
// implementar logica aqui
|
||||
return ""
|
||||
text.toLowerCase();
|
||||
|
||||
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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user