题解 | #高频数据类型#
高频数据类型
https://www.nowcoder.com/practice/687425f78096428baa58fbdcf024244a
let count = {} let max = [0] typearr = array.map(item => { const type = item instanceof Object ? 'object' : Object.prototype.toString.call(item).slice(8,-1).toLowerCase() if(count[type] == undefined){ count[type] = 1 }else{ count[type] += 1 } console.log(count[type], max[max.length-1]); if(count[type]>max[max.length-1]){ max = [type,count[type]] }else if(count[type]==max[max.length-1]){ max.unshift(type) } }) console.log(max); return max