forked from M3-Academy/challenge-algorithms-v2.0
Merge pull request 'Feat(Desafio_2.9): Cria desafio 2.9' (#9) from Feature/Desafio_2.9 into develop
Reviewed-on: #9
This commit is contained in:
commit
b218c48e66
@ -1,4 +1,18 @@
|
||||
export function mostUsedChar(text) {
|
||||
// implementar logica aqui
|
||||
return ""
|
||||
const tl = text.length;
|
||||
const freq = {};
|
||||
let maxFreq = 0;
|
||||
let maxChar;
|
||||
for (let i = 0; i < tl; ++i){
|
||||
const isPair = (text.charCodeAt(i) & 0xF800) == 0xD800;
|
||||
const c = isPair ? text.substr(i++, 2) : text[i];
|
||||
const f = (freq[c] || 0) + 1;
|
||||
freq[c] = f;
|
||||
if (f > maxFreq){
|
||||
maxFreq = f;
|
||||
maxChar = c;
|
||||
}
|
||||
}
|
||||
return maxChar
|
||||
}
|
Loading…
Reference in New Issue
Block a user