forked from M3-Academy/challenge-algorithms-v2.0
feature: resolve exercício 09-mostRepeatedChar
This commit is contained in:
parent
26ec68f084
commit
32929413f6
@ -1,4 +1,18 @@
|
||||
export function mostUsedChar(text) {
|
||||
// implementar logica aqui
|
||||
return ""
|
||||
let charObj = {};
|
||||
let maxCount = 0;
|
||||
let maxChar = "";
|
||||
|
||||
for (let char of text) {
|
||||
charObj[char] = ++charObj[char] || 1;
|
||||
}
|
||||
|
||||
for (let char in charObj) {
|
||||
if (charObj[char] > maxCount) {
|
||||
maxCount = charObj[char];
|
||||
maxChar = char;
|
||||
}
|
||||
}
|
||||
|
||||
return maxChar;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user