challenge-algorithms-v2.0/09-mostRepeatedChar/index.js

22 lines
388 B
JavaScript
Raw Permalink Normal View History

export function mostUsedChar(text) {
2022-10-31 20:50:50 +00:00
// implementar logica aqui
text = text.split('').sort();
let cont1 = 0;
let cont2 = 0;
let maior = '';
for (let i = 1; i < text.length; i++) {
if (text[i] != text[i - 1]) {
if (cont2 > cont1) {
cont1 = cont2;
maior = text[i - 1];
}
cont2 = 1;
} else {
cont2++;
}
}
return maior;
}