forked from M3-Academy/challenge-algorithms-v2.0
Merge branch 'feature/mostRepeatedChar' into development
This commit is contained in:
commit
c7c04e054b
@ -1,4 +1,18 @@
|
|||||||
export function mostUsedChar(text) {
|
export function mostUsedChar(text) {
|
||||||
// implementar logica aqui
|
// implementar logica aqui
|
||||||
return ""
|
let count = 0;
|
||||||
|
let char = " ";
|
||||||
|
let save = {};
|
||||||
|
text.split("").forEach((letter) => {
|
||||||
|
if(save[letter]){
|
||||||
|
save[letter] += 1;
|
||||||
|
} else {
|
||||||
|
save[letter] = 1;
|
||||||
|
}
|
||||||
|
if(save[letter] > count){
|
||||||
|
count = save[letter];
|
||||||
|
char = letter;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return char;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user