{
"name": "油",
"profit": 19.01,
"config": {
"colo": 0
}
},
{
"name": "米",
"profit": 129.08,
"config": {
"colo": 0
}
},
{
"name": "盐",
"profit": 539.11,
"config": {
"colo": 0
}
}
]
let data2 = [
{
"spot": "186.00",
"name": "油",
"run_info": {
"buy_value": 8902.3,
"buy_amount": 3.623
},
"status": 0,
"buy_time": 1718793250
},
{
"spot": "186.00",
"name": "油",
"run_info": {
"buy_value": 8902.3,
"buy_amount": 3.623
},
"status": 0,
"buy_time": 1718723250
},
{
"spot": "186.00",
"name": "油",
"run_info": {
"buy_value": 8902.3,
"buy_amount": 3.623
},
"status": 0,
"buy_time": 1711793250
},
{
"spot": "186.00",
"name": "米",
"run_info": {
"buy_value": 8902.3,
"buy_amount": 3.623
},
"status": 0,
"buy_time": 1712793250
},
{
"spot": "186.00",
"name": "盐",
"run_info": {
"buy_value": 8902.3,
"buy_amount": 3.623
},
"status": 0,
"buy_time": 1718793250
},
{
"spot": "186.00",
"name": "盐",
"run_info": {
"buy_value": 8902.3,
"buy_amount": 3.623
},
"status": 0,
"buy_time": 1718743250
},
{
"spot": "186.00",
"name": "面",
"run_info": {
"buy_value": 8902.3,
"buy_amount": 3.623
},
"status": 0,
"buy_time": 1718723250
},
{
"spot": "186.00",
"name": "蒜",
"run_info": {
"buy_value": 8902.3,
"buy_amount": 3.623
},
"status": 0,
"buy_time": 1718193250
},
{
"spot": "186.00",
"name": "蒜",
"run_info": {
"buy_value": 8902.3,
"buy_amount": 3.623
},
"status": 1,
"buy_time": 1711793250
},
{
"spot": "186.00",
"name": "葱",
"run_info": {
"buy_value": 8902.3,
"buy_amount": 3.623
},
"status": 1,
"buy_time": 1718793212
}
]
问了GPT,可能文化水平有限,得不到我需要的答案
以上有两个数组,data1的数组是从API得来的,数组内的对象是不固定的,可能是多个,但数组对象里的name是唯一的,不会重复,
data2数组里的对象也是不固定的,name可能会有重复
我需要根据以下条件,从data2里拿到我想要的数据
根据data1的数据,name为前提,每个key从data2筛选出最多3条数据,比如data1里的”油“,如果data2里存在,并且大于等于3,则跳过油,则这个对象从data2里拿到了0个对象,”米“在data2里只有一条,则从data2里取除去有”米“且status为1(优先)的两个随机对象,如果没有status为1的对象,则取status为0的对象,data1的”盐“在data2里有两个对象,则在data2里取除去”盐“的一个随机对象,以此类推..
根据上面例子,”油“从data2获取了0个对象,”米“从data2获取了2个对象,”盐“获取了1个对象,打印出来就是符合三个对象