Here is a piece of code. Here is the desired functionality. What is wrong, and how to fix it.
The function should merge all overlapping closed intervals and return non-overlapping intervals sorted by start value. Identify the bugs and provide a corrected implementation.
function merge_intervals(intervals)
Input is an array of integer pairs. Output is an array of merged integer pairs.
Example: [[1,3],[2,6],[8,10]] should produce [[1,6],[8,10]]. Intervals that only touch, such as [1,2] and [2,4], overlap.
def merge_intervals(intervals):