I did a findMaxChar count algorithm practice, manage to get it to worked but my call method can be improved.
const myStr = 'Lorem Ipsummm'
function findRepeatable(myStr){
let charMap = {}
for(let char of myStr){
if(charMap[char]) {
charMap[char]++
}else{
charMap[char] = 1
}
}
return charMap
}
function findMostRepeated(obj){
let maxChar = '',
max = 0
for(let char in obj){
if(obj[char] > max){
max = obj[char]
maxChar = char
}
}
return `${maxChar}: ${max}`
}
console.log(findMostRepeated(findRepeatable(myStr)))
I'm passing function as argument, how can I make it to chain like this
findMostRepeated()
.findRepeatable()