先上代码,formatter希望返回组装后的数据
var olda = [
{
flight: 'hu7305',
from: 'lhw',
to: 'ybp'
},
{
flight: 'hu7306',//new中没有,state=del
from: 'lhw',
to: 'ybp'
},
];
var newa = [
{
flight: 'hu7305',//old中有,忽略
from: 'lhw',
to: 'ybp'
},{
flight: 'hu7777',//old中没有,state=add
from: 'www',
to: 'qqq'
}
];
function formatter(a, b){
...
return ([//希望返回如下的数据
{
flight: 'hu7306',//del
from: 'lhw',
to: 'ybp',
state: 'del'
},{
flight: 'hu7777',//add
from: 'www',
to: 'qqq',
state: 'add'
}
])
}
formatter(olda, newa);
规则:单个对象中的flight、from、to三者的值任一不同则视为不同的数据,需要返回;在olda中有而newa中没有时state为del,在olda没有而newa中有则state为add。
慕田峪7331174
相关分类