forked from M3-Academy/challenge-algorithms-v2.0
feat(mostrepeatedchar):aplicando a função ao testee 9
This commit is contained in:
parent
82e915ce28
commit
3c55eae119
@ -1,4 +1,12 @@
|
||||
export function mostUsedChar(text) {
|
||||
// implementar logica aqui
|
||||
return ""
|
||||
const arr = text.split("");
|
||||
let counts = {};
|
||||
arr.forEach((count) => {
|
||||
counts[count] = (counts[count] || 0) + 1;
|
||||
});
|
||||
|
||||
const maxVal = Math.max(...Object.values(counts));
|
||||
const num = Object.keys(counts).find((key) => counts[key] === maxVal);
|
||||
return num;
|
||||
}
|
Loading…
Reference in New Issue
Block a user