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

19 lines
602 B
JavaScript
Raw Permalink Normal View History

export function mostUsedChar(text) {
// implementar logica aqui
2022-10-28 13:53:09 +00:00
let result = '';
let mostUsedCount = 0;
for (const letter of text) {
let countLetter = 0;
for (const letterToCount of text) {
if (letterToCount === letter) {
countLetter++;
}
}
if (countLetter > mostUsedCount) {
mostUsedCount = countLetter;
result = letter;
}
}
return result;
}