feat: Resolve o exercício 09-mostRepeatedChar

This commit is contained in:
SamuelCondack 2022-10-27 17:39:33 -03:00
parent 3e366ffee8
commit a787d5710b

View File

@ -1,4 +1,21 @@
export function mostUsedChar(text) { export function mostUsedChar(text) {
// implementar logica aqui // implementar logica aqui
return "" 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;
} }