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

18 lines
474 B
JavaScript
Raw Normal View History

export function mostUsedChar(text) {
let cont = 0, contador = 0, finalVlue;
let texto = text.split("");
for (let i = 0; i < texto.length; i++) {
cont = 0;
for (let j = 0; j < texto.length; j++) {
if (texto[i].toUpperCase() === texto[j].toUpperCase()) {
cont++
}
}
if (cont >= contador) {
contador = cont;
finalVlue = texto[i]
}
}
return finalVlue;
}