我正在尝试重新排列以下数组。其实排序是
基于sourcelocation.orderindex
,每个对象都有其对应的
另一个对象(与rider_id
相同)以及is_dropoff
字段true
,我想以以下方式对数组重新排序。
第1步:sourceindex
为0
的对象应放在顶部
案例前3个对象将位于最前面,下一个对象必须比sourcelocation.order
大0
,并且is_dropoff
为真,请注意,destinationlocation.orderindex
不能大于即将出现的对象{{1} }值。
sourcelocation.orderindex
以下必须是我期望的答复
let inputSet = [
{
"sourcelocation": {
"orderindex": "0"
},
"destinationlocation": {
"orderindex": "1"
},
"rider_ids": "2b7116ea3dead9870b828a1v"
},
{
"sourcelocation": {
"orderindex": "0"
},
"destinationlocation": {
"orderindex": "1"
},
"rider_ids": "4b7116ea3dead9870b828a19"
},
{
"sourcelocation": {
"orderindex": "0"
},
"destinationlocation": {
"orderindex": "3"
},
"rider_ids": "548e653d56060c83838b772e"
},
{
"rider_ids": "2b7116ea3dead9870b828a1v",
"is_dropoff": true,
"address": {
"orderindex": "1"
}
},
{
"rider_ids": "4b7116ea3dead9870b828a19",
"is_dropoff": true,
"address": {
"orderindex": "1"
}
},
{
"rider_ids": "548e653d56060c83838b772e",
"is_dropoff": true,
"address": {
"orderindex": "3"
}
},
{
"sourcelocation": {
"orderindex": "2"
},
"destinationlocation": {
"orderindex": "3"
},
"rider_ids": "5b8e676d56060c83838b772e"
},
{
"rider_ids": "5b8e676d56060c83838b772e",
"is_dropoff": true,
"address": {
"orderindex": "3"
}
}
]