题解 | #高频数据类型#
高频数据类型
http://www.nowcoder.com/practice/687425f78096428baa58fbdcf024244a
const _findMostType = array => {
// 补全代码
var obj={}
array.forEach((item,index)=>{
if(obj[typeof item]){obj[typeof item]++}
else{
obj[typeof item]=1
}
})
var maxValue = Math.max(...Object.values(obj))
var newarrLeft=[]
var newarrRight=[]
Object.keys(obj).forEach((key)=>{
if (obj[key]==maxValue) {
newarrLeft.push(key)
newarrRight.push(key)
}
})
newarrRight.reverse()
newarrRight.push(maxValue)
newarrLeft.push(maxValue)
return newarrLeft ||newarrRight
}
结果对,不给通过,大伙看着改吧