字符串中出现次数最多的字符

let str = 'hellochinahellochinahelloj'
  let strArr = str.split('').sort()
  console.log(strArr)
  let muli = ''
  let letter = 1
  let maxMuli = strArr[0]
  let maxLetter = 1
  for (let i = 1; i < strArr.length; i++) {
    if(strArr[i-1] === strArr[i]) {
      letter = letter + 1
      muli = strArr[i]
    } else{
      if(maxLetter < letter) {
        maxLetter = letter
        maxMuli = muli
        
      }
      letter = 1
    }
  }
  console.log('maxMuli', maxMuli)
  console.log('maxLetter', maxLetter)
上一篇:伪元素和伪类


下一篇:Redis数据类型