SOURCE

let array = [[1, 2], [2, 3], [4, 5], [10, 12], [5, 8], [15, 17], [13, 15],]
let copyAry = JSON.parse(JSON.stringify(array))
function getCombineList(array) {
    if (!(Array.isArray(array))) { return }
    const list = []
    for (let m = 0; m < array.length; m++) {
        const [prevA, prevB] = array[m]
        for (let n = 1; n < array.length - 1; n++) {
            const [nextA, nextB] = array[n]
            if (prevB === nextA) {
                list.push([prevA, nextB])
                copyAry.splice(m, 1, null)
                copyAry.splice(n, 1, null)
                break
            }
        }
    }
    return list
}

const list = getCombineList(array)
copyAry.forEach(ele => {
    if (!ele) { return }
    list.push(ele)
})
console.log('log...', list)
console 命令行工具 X clear

                    
>
console