题解 | 高频数据类型

高频数据类型

https://www.nowcoder.com/practice/687425f78096428baa58fbdcf024244a

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
  </head>
  <body>
    <script type="text/javascript">
      const _findMostType = (array) => {
        // 补全代码
        let map = new Map();
        let arr = [];
        array.forEach((item) => {
          let type = typeof item;
          map.set(type, (map.get(type) || 0) + 1);
        });

        let maxNum = Math.max(...map.values());
        for (let [key, value] of map) {
          if (value === maxNum) {
            arr.push(key);
          }
        }
        arr.push(maxNum)
        return JSON.stringify(arr);
      };
      console.log(
        _findMostType([1, "1", {}, {}, 2, 3, 4, 3, 3, "", "", "", "", ""])
      );
    </script>
  </body>
</html>

全部评论

相关推荐

节后就六月了,六月找暑期实习还有戏吗?
佛系的芝士不放弃:不要急嘛,如果你能接受8月底或者9月初再投简历的话,都不要急,6月底会放一批实习出来,然后7月初再出去实习,因为这个时间段很大佬已经实习完准备回校准备秋招了,一堆实习空缺岗。
点赞 评论 收藏
分享
VirtualBool:都去逗他了?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务