feat: resolve mostRepeatedChar
This commit is contained in:
parent
e50b6fb5ae
commit
d68e3bd4d9
@ -1,4 +1,13 @@
|
||||
export function mostUsedChar(text) {
|
||||
// implementar logica aqui
|
||||
return ""
|
||||
const arr = text.split("");
|
||||
|
||||
let timesRepeat = {};
|
||||
arr.forEach((count) => {
|
||||
timesRepeat[count] = (timesRepeat[count] || 0) + 1;
|
||||
})
|
||||
|
||||
const maxVal = Math.max(...Object.values(timesRepeat));
|
||||
const num = Object.keys(timesRepeat).find((key) => timesRepeat[key] === maxVal);
|
||||
return num;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user