21 lines
673 B
JavaScript
21 lines
673 B
JavaScript
export function mostUsedChar(text) {
|
|
// implementar logica aqui
|
|
let SIZE = 256
|
|
let count = new Array(SIZE);
|
|
for (let n = 0; n < SIZE; n++) {
|
|
count[n] = 0;
|
|
}
|
|
let len = text.length;
|
|
for (let i = 0; i < len; i++) {
|
|
count[text[i].charCodeAt(0)] += 1;
|
|
}
|
|
let max = -1;
|
|
let result = ' ';
|
|
for (let i = 0; i < len; i++) {
|
|
if (max < count[text[i].charCodeAt(0)]) {
|
|
max = count[text[i].charCodeAt(0)];
|
|
result = text[i];
|
|
}
|
|
}
|
|
return result;
|
|
} |