![](https://img2018.cnblogs.com/blog/1853166/202001/1853166-20200126170350725-1280437990.png) ![](https://img2018.cnblogs.com/blog/1853166/202001/1853... ...
export default (arr) => {
// 進行升序排序
arr.sort((a, b) => a - b)
// 聲明一個空數組用來存儲奇偶排序後的數組
let r = []
// 記錄奇數、偶數位下標
let odd = 1
let even = 0
// 對數組進行遍歷
arr.forEach(item => {
if (item % 2 === 1) {
r[odd] = item
odd += 2
} else {
r[even] = item
even += 2
}
})
return r
}