SOURCE

//合并方法
function comb([a1, a2], [b1, b2]) {
    let flag=+(a1 >= b1) << 3 | +(a2 >= b1) << 2 | +(a1 > b2) << 1 | +(a2 >= b2)
    console.log('合并',[a1, a2], [b1, b2],flag)
    switch (flag) {
        case 0b0100:
            return [a1, b2]
        case 0b0101:
            return [a1, a2]
        case 0b1100:
            return [b1, b2]
        case 0b0000:
            return []
        case 0b1111:
            return []
        case 0b1101:
            return [b1, a2]
    }
}
//现有数组
let res=[[0,1],[2,3],[4,6]]

//要插入的数组
let insert=[1,4]

let combFinal=[]
for(let i=0;i<res.length;i++){
    let combRes=comb(insert,res[i])
    if(combRes.length===0){
        combFinal.push(res[i])
    }else{
        insert=combRes
    }
}
combFinal.push(insert)
console.log(combFinal.sort(function(a,b){return b[0]-a[0]}))
console 命令行工具 X clear

                    
>
console