mostRepeatedChar
This commit is contained in:
parent
b2ddc722a1
commit
dc3e6b1151
@ -1,17 +1,17 @@
|
|||||||
export function mostUsedChar(text) {
|
export function mostUsedChar(text) {
|
||||||
// implementar logica aqui
|
|
||||||
const total = text.split("");
|
const total = text.split("");
|
||||||
|
|
||||||
let repeat = {};
|
let repeat = {};
|
||||||
total.forEach((count) => {
|
total.forEach((count) => {
|
||||||
repeat[count] = (repeat[count] || 0) + 1;
|
repeat[count] = (repeat[count] || 0) + 1;
|
||||||
})
|
});
|
||||||
|
|
||||||
const maxVal = Math.max(...Object.values(repeat));
|
const maxVal = Math.max(...Object.values(repeat));
|
||||||
const num = Object.keys(repeat).find((key) => repeat[key] === maxVal);
|
const num = Object.keys(repeat).find((key) => repeat[key] === maxVal);
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
console.log(mostUsedChar("fdgdfgff"))//("f")
|
|
||||||
console.log(mostUsedChar("Lorem ipsum"))//("m")
|
console.log(mostUsedChar("fdgdfgff")); //("f")
|
||||||
console.log(mostUsedChar("adsassdasd"))//("s")
|
console.log(mostUsedChar("Lorem ipsum")); //("m")
|
||||||
console.log(mostUsedChar("testeeeee"))//("e")
|
console.log(mostUsedChar("adsassdasd")); //("s")
|
||||||
|
console.log(mostUsedChar("testeeeee")); //("e")
|
||||||
|
Loading…
Reference in New Issue
Block a user