查数组中重复最多的字段
Array.prototype.repeat = function(...indexArr){let shipObj = this.reduce((pre, cur)=>{
pre ? pre++ : pre = 1;
return pre;
}, {})
let valList = Object.values(shipObj).sort((m,n)=>n-m);
if(!indexArr.length){
indexArr =
}
let resArr = indexArr.map(index=> valList||null).filter(v=>v!==null)
Object.keys(shipObj).forEach(key=>{
resArr.some((val,i)=>{
if(shipObj === val){
resArr = ];
return true;
}
return false
})
})
return resArr.length > 1 ? resArr : resArr||[];
}
文档来源:51CTO技术博客https://blog.51cto.com/u_10585798/3269290
页:
[1]