思路:先把数组内的元素进行排序
然后对数组遍历通过index来进行单双数判断头部添加还是尾部添加
实现:
let arrCount = [1,4,5,8,89,44,15,13,110,120,150]
let newCount = []
arrCount = arrCount.sort(function (a,b){
return b-a
})
arrCount.forEach((item,index)=>{
if (index%2){
newCount.push(item)
}else {
newCount.unshift(item)
}
})
console.log(newCount) // [1, 5, 13, 44, 110, 150, 120, 89, 15, 8, 4]