2022-10-27 15:07:13 +00:00
|
|
|
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;
|
2022-10-27 15:07:13 +00:00
|
|
|
}
|