1.键值对法 (我最喜欢,简单易懂)

Array.prototype._RepeatMost = function () {
  let _this = [...this];
  const obj = {};
  let maxTerm = 1;
  let key = null;
  _this.forEach((item, index) => {
    if (obj[item] === undefined) {
      obj[item] = 1;
    } else {
      obj[item] = ++obj[item];
      if (maxTerm < obj[item]) {
        maxTerm = obj[item];
        key = item;
      }
    }
  })
  return { [key]: maxTerm }
}
console.log(ary._RepeatMost())

 

相关文章:

  • 2021-08-29
  • 2022-02-20
  • 2021-11-29
  • 2022-12-23
  • 2021-06-25
  • 2021-11-29
  • 2022-02-07
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案