Merge Intervals 

Run Settings
LanguageJavaScript
Language Version
Run Command
/** * @param {number[][]} intervals * @return {number[][]} */ var merge = function(intervals) { let uniqueIntervals=[]; let curr=[intervals[0]]; intervals= intervals.sort((a,b)=>(a[0]-b[0])) for(let x of intervals){ //console.log("int ",uniqueIntervals, " ",curr," ",x) if(curr[1]>=x[0]){ //console.log("if") curr[1]=Math.max(curr[1] , x[1]) //curr[1] = 'sm' } else{ console.log(x) uniqueIntervals.push(x); curr=x; } } return uniqueIntervals }; console.log(merge([[1,3],[2,6],[8,10],[15,18]]))
Editor Settings
Theme
Key bindings
Full width
Lines