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

27 lines
720 B
JavaScript
Raw Permalink Normal View History

export function mostUsedChar(text) {
2022-10-28 12:20:54 +00:00
let order = text.toLowerCase().split('').sort();
let finalResult = "";
let letterMostAppears = 0;
//console.log(order) ---> verificar se transformou em array e ordenou
for(let i=0; i<order.length; i++){
let count = 0;
for(let j=1; j<order.length; j++){
//console.log(`Resultado: ${order[i]}, ${order[j]} `)
if(order[i] === order[j]){
count++;
}
}
if (count > letterMostAppears){
letterMostAppears = count;
finalResult = order[i];
}
}
return finalResult;
}