Daily-Interview-Question icon indicating copy to clipboard operation
Daily-Interview-Question copied to clipboard

我也来试试

Open DingSJi opened this issue 1 year ago • 0 comments

const fn = function(str){ let arr = str.split("") let obj = {} let maxStr = "", maxNum = 0; arr.reduce((pre, next) => { if(pre in obj){ if(pre == next) obj[pre]++ }else{ obj[pre] = 1 } return next },arr[0]) console.log(obj) for(let key in obj){ if(maxNum < obj[key]){ maxNum = obj[key] maxStr = key } } return ${maxStr}-${maxNum} }

console.log(fn('aaaaaabbbba'))

DingSJi avatar Aug 27 '24 07:08 DingSJi