实例对象数组 let intersection = [{1,3}, {2,5}, {-3,7}, {6,9}]。
对数组 Arry = [a, b, c, d, e] 进行循环。
a→b,
a→c,
a→d,
a→e,
b→c,
b→d,
b→e,
c→d,
c→e,
d→e
这样匹配比对。
let intersection = [
{ max: 1, min: -5 },
{ max: 4, min: 1 },
{ max: 9, min: 4 },
{ max: 6, min: 2 },
{ max: 2, min: 1 },
{ max: 9, min: 2 }
]
for (let i = 0; i < intersection.length; i++) {
for (let j = i + 1; j < intersection.length; j++) {
if (
intersection[i].max > intersection[j].min ||
intersection[i].min < intersection[j].max
) {
console.log('数据存在交集!!')
}
}
}