How to get the remaining interval in an array by js

arr = [
    [500,1000],
    [2000,4000],
    [5000,8000],
    [8000,9000],
    [10000,12000],
    [14000,20000],
    [23000,30000],
]

the range of intervals represented by the known array arr [500 ~ (1, 000)]

1 the same parts should be merged into 5000-9000

.

2 find the residual interval of the residual space, for example, 0500 1000-2000 4000-5000. Wait

Mar.12,2021

    const arr = [
        [500,1000],
        [2000,4000],
        [5000,8000],
        [8000,9000],
        [10000,12000],
        [14000,20000],
        [23000,30000],
    ];
        let newArr = arr.reduce((a,v)=>{
        if(typeof(a[0])=="number"){
          if(a[1] == v[0]) return [a[0],v[1]]
          //console.log([a,v])
          return [a,v]
        }else{
          if(a[a.length-1][1]!=v[0]) { 
            a.push(v)
          }else{ 
            a[a.length-1][1] = v[1]
          }
          return a
        }
        })
    console.log(newArr) 
    let resArr = newArr.reduce((a,v)=>{
      if(typeof(a[0])=="number"){
        if(a[0]!=0) return [[0,a[0]],[a[1],v[0]],[v[1],v[1]]]
        return [[a[1],v[0]],[v[1],v[1]]] 
      }else{ 
        a[a.length-1][1]  = v[0];
        if(a.length!=newArr.length) a.push([v[1],v[1]])
      }
      return a 
    })
    console.log(resArr)
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3c54c-2ba81.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3c54c-2ba81.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?