You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
function getMostChar(str){
let i = 0
let obj = []
while(i<str.length){
let val = str.charAt(i)
let count = 0
while(i<str.length&&str.charAt(i)===val){
count++
i++
}
let key = count+'-'+val
obj[key]=count
}
let maxValue = 0
let result = {}
for(let key in obj){
if(obj[key]>maxValue){
result = {}
maxValue = obj[key]
let val = key.split('-')[0]
let k = key.split('-')[1]
result[k] = val
}else if(obj[key]===maxValue){
let val = key.split('-')[0]
let k = key.split('-')[1]
if(!result.hasOwnProperty(k)){
result[k] = val
}
}
}
return result
}
console.log(getMostChar('abbkejsbcccwqaaaqqqwwwccc'))
Activity
Jeckhenry commentedon Oct 19, 2020
kkk48ku commentedon Oct 19, 2020
syc666 commentedon Oct 19, 2020
sisterAn commentedon Oct 20, 2020
mynzk commentedon Dec 8, 2020
xllpiupiu commentedon Oct 5, 2021
xllpiupiu commentedon Oct 5, 2021
fengmiaosen commentedon Aug 1, 2022
AlexZhang11 commentedon May 23, 2024
function getMostChar(str){
let i = 0
let obj = []
while(i<str.length){
let val = str.charAt(i)
let count = 0
while(i<str.length&&str.charAt(i)===val){
count++
i++
}
let key = count+'-'+val
obj[key]=count
}
let maxValue = 0
let result = {}
for(let key in obj){
if(obj[key]>maxValue){
result = {}
maxValue = obj[key]
let val = key.split('-')[0]
let k = key.split('-')[1]
result[k] = val
}else if(obj[key]===maxValue){
let val = key.split('-')[0]
let k = key.split('-')[1]
if(!result.hasOwnProperty(k)){
result[k] = val
}
}
}
return result
}
console.log(getMostChar('abbkejsbcccwqaaaqqqwwwccc'))