mostRepeatedChar
This commit is contained in:
parent
b2ddc722a1
commit
dc3e6b1151
@ -1,17 +1,17 @@
|
||||
export function mostUsedChar(text) {
|
||||
// implementar logica aqui
|
||||
const total = text.split("");
|
||||
const total = text.split("");
|
||||
|
||||
let repeat = {};
|
||||
total.forEach((count) => {
|
||||
repeat[count] = (repeat[count] || 0) + 1;
|
||||
})
|
||||
let repeat = {};
|
||||
total.forEach((count) => {
|
||||
repeat[count] = (repeat[count] || 0) + 1;
|
||||
});
|
||||
|
||||
const maxVal = Math.max(...Object.values(repeat));
|
||||
const num = Object.keys(repeat).find((key) => repeat[key] === maxVal);
|
||||
return num;
|
||||
const maxVal = Math.max(...Object.values(repeat));
|
||||
const num = Object.keys(repeat).find((key) => repeat[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")
|
||||
|
||||
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