Let's say we have a List of ranges expressed in arrays with two elements [from, to].
When we add a new array range like [5,8], it should check in List if there is a closest range and then replace it with the new range value. An example is provided below:
Example 1
var List = [[1,2], [3,4], [6,7], [9,10]]
var newData = [5,8]
Expected Output:
[[1,2], [3,4], [5,8], [9,10]]
The [6,7] range is already included in [5,8]
Example 2
var List = [[1,3], [4,6], [8,10]]
var newData = [5,9]
Expected Output:
[[1,3], [4,10]]