mostRepeatedCh
This commit is contained in:
parent
b4b48956cd
commit
dceca730b9
@ -1,4 +1,17 @@
|
|||||||
export function mostUsedChar(text) {
|
export function mostUsedChar(text) {
|
||||||
// implementar logica aqui
|
// implementar logica aqui
|
||||||
return ""
|
const total = text.split("");
|
||||||
}
|
|
||||||
|
let timesRepeat = {};
|
||||||
|
total.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;
|
||||||
|
}
|
||||||
|
console.log(mostUsedChar("fdgdfgff"))//("f")
|
||||||
|
console.log(mostUsedChar("Lorem ipsum"))//("m")
|
||||||
|
console.log(mostUsedChar("adsassdasd"))//("s")
|
||||||
|
console.log(mostUsedChar("testeeeee"))//("e")
|
Loading…
Reference in New Issue
Block a user