javascript explanation
append new interval to list of intervals\n sort by beg time\n then do merge intervals \n\n(I know sorting will raise time to O(nlogn) and there are some solutio
* append new interval to list of intervals\n* sort by beg time\n* then do merge intervals \n\n(I know sorting will raise time to O(nlogn) and there are some solutions out there that yield O(n))\n\n```javascript\nconst insert = (intervals, newInterval) => {\n    if(!intervals) return [];\n    const ans = new Array();\n    \n    intervals.push(newInterval);\n    intervals.sort((a, b) => a[0] - b[0]);\n    \n    if(intervals.length === 1) return intervals;\n    const prev = [intervals[0][0], intervals[0][1]];\n    for(let i = 1; i < intervals.length; i++) {\n        const curr = intervals[i];\n        if(isOverlap(prev, curr)) {\n            prev[0] = Math.min(prev[0], curr[0]);\n            prev[1] = Math.max(prev[1], curr[1]);\n        } else {\n            ans.push([...prev]);\n            prev[0] = curr[0];\n            prev[1] = curr[1];\n        }\n        \n        if(i === intervals.length - 1) ans.push([...prev])\n    }\n    \n    return ans;\n};\n\nconst isOverlap = (prev, curr) => {\n    return  prev[1] >= curr[0] && prev[1] <= curr[1]\n            || prev[0] >= curr[0] && prev[0] <= curr[1]\n            || prev[0] <= curr[0] && prev[1] >= curr[1];\n};\n```
['JavaScript']