forked from M3-Academy/challenge-algorithms-v2.0
24 lines
511 B
JavaScript
24 lines
511 B
JavaScript
export function mostUsedChar(text) {
|
|
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;
|
|
} |