feat: Resolve o exercício 09-mostRepeatedChar
This commit is contained in:
parent
3e366ffee8
commit
a787d5710b
@ -1,4 +1,21 @@
|
||||
export function mostUsedChar(text) {
|
||||
// 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user