I have encountered similar questions, however, the provided answers do not resolve my specific issue.
The data I have is an array of range objects, each with the following properties:
start
: Integer, indicating the start of the range,end
: Integer, indicating the end of the range.
The desired output is:
An array of non-overlapping range objects that cover the same ranges as the input, sorted from the smallest start to the largest start. Two ranges do not overlap if:
range1.start <= range2.start
, andrange1.end >= range2.start
Input:
[
{ start: 8, end: 10 },
{ start: 5, end: 7 },
{ start: 9, end: 12 },
{ start: 2, end: 6 },
]
Output:
[
{ start: 2, end: 7 },
{ start: 8, end: 12 }
]
I have attempted various solutions found online for merging overlapping intervals, but they have not provided the desired result.
Thank you.