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

26 lines
544 B
JavaScript

export function mostUsedChar(text) {
// implementar logica aqui
let newStr = text.replace(' ', '').split('');
let count = 0;
let countControl = 0;
let strRepeat = '';
for(let i = 0; i < newStr.length; i++){
for(let j = 0; j < newStr.length; j++){
if(newStr[i] === newStr[j]){
count++;
}
}
if(count > countControl){
strRepeat = newStr[i];
countControl = count;
}
count = 0;
}
return strRepeat;
}