1 回答
TA贡献1839条经验 获得超15个赞
我想我已经明白了:
function reorder(){
var pinnedTasksPos = []
var pinnedTasksNeg = []
var regularTasksPos = []
var regularTasksNeg = []
var finishedTasksPos = []
var finishedTasksNeg = []
for (e=0; e<tasks.length; e++){
let i = tasks[e]
console.log(i)
if(i.pinned){
if(i.dueDaysDiff >= 0) {
pinnedTasksPos.push(i)
} else{
pinnedTasksNeg.push(i)
}
} else if(i.done){
if(i.dueDaysDiff >= 0) {
finishedTasksPos.push(i)
} else{
finishedTasksNeg.push(i)
}
} else{
if(i.dueDaysDiff >= 0) {
regularTasksPos.push(i)
} else{
regularTasksNeg.push(i)
}
}
}
pinnedTasksPos.sort(compare)
pinnedTasksNeg.sort(compare).reverse()
regularTasksPos.sort(compare)
regularTasksNeg.sort(compare).reverse()
finishedTasksPos.sort(compare)
finishedTasksNeg.sort(compare).reverse()
var newarr = [...pinnedTasksPos, ...pinnedTasksNeg, ...regularTasksPos, ...regularTasksNeg, ...finishedTasksPos, ...finishedTasksNeg]
return(newarr.reverse())
}
function compare(a, b){
if(a.dueDaysDiff < b.dueDaysDiff){
return -1
}
if(a.dueDaysDiff > b.dueDaysDiff){
return 1
}
return 0
}
添加回答
举报