temp(){
// 可以基于filter方法,结合组合方法实现,其中部分代码借鉴网上资料
const arr1 = [1,2,3,4,5,6,7,8,9],
arr2 = [5,6,7,8,9];
// 交集
let intersection = arr1.filter(function (val) { return arr2.indexOf(val) > -1 }) //写法1:indexOf
let intersection = arr1.filter(item => arr2.some(ele => ele === item)) //写法2:some
// 并集
let union = arr1.concat(arr2.filter(function (val) { return !(arr1.indexOf(val) > -1) }))
// 补集 两个数组各自没有的集合
let complement = arr1.filter(function (val) { return !(arr2.indexOf(val) > -1) })
.concat(arr2.filter(function (val) { return !(arr1.indexOf(val) > -1) }))
// 差集
let diff = arr1.filter(function (val) { return arr2.indexOf(val) === -1 }) //写法1:indexOf
let diff = arr1.filter(item => !arr2.some(ele => ele === item)) //写法2:some
console.log('arr1: ', arr1);
console.log('arr2: ', arr2);
console.log('交集', intersection);
console.log('并集', union);
console.log('补集', complement);
console.log('差集', diff);
},
//整合汽车相同参数
integerPro(){
const diff = this.data.diff //差集
let pkcars = this.data.pkcars //完整数据集
// 循环组装数据
pkcars.map((e,index)=>{
// console.log('integerPro,e',e)
const ownerpros = e.propertylist.filter(item => !diff.some(ele => ele.propertyId === item.propertyId))
const integerPro = [...diff,...ownerpros]
pkcars[index].propertylist = integerPro.sort(this.compare('propertyId'))
})
this.setData({ pkcars })
// console.log('pkcars',pkcars)
},