Intersection of intervals
. Does not simplify result. Keeps extra object properties on intervalB
.
interalA
and interalB
can have different structure.
Accept array of intervals. Doesn't mutate input. Output keeps intervalB
structure.
Intervals arrays have to be sorted.
interval(s) A | interval(s) B | result |
---|---|---|
{ from: 0, to: 4 } | { start: 3, end: 7, foo: 'bar' } | [{ start: 3, end: 4, foo: 'bar' }] |
{ start: 0, end: 10 } | [{ start: 2, end: 5}, { start: 5, end: 8}] | [{ start: 2, end: 5 }, { start: 5, end: 8 }] |
[{ start: 0, end: 4 }, { start: 8, end: 11 }] | [{ start: 2, end: 9 }, { start: 10, end: 13 }] | [{ start: 2, end: 4 }, { start: 8, end: 9 }, { start: 10, end: 11 }] |
Test if intervalA
is after or adjacent intervalB
.
intervalA | intervalB | result |
---|---|---|
{ start: 5, end: 10} | { start: 3, end: 4 } | true |
{ start: 5, end: 10} | { start: 3, end: 6 } | false |
Test if intervalA
is before or adjacent intervalB
.
intervalA | intervalB | result |
---|---|---|
{ start: 0, end: 2} | { start: 3, end: 7 } | true |
{ start: 0, end: 5} | { start: 3, end: 7 } | false |
Test if intervalA
occurs in intervalB
. intervalsB
act as boundaries. Can share starting and/or ending point.
intervalA | intervalB | result |
---|---|---|
{ start: 2, end: 6} | { start: 0, end: 10 } | true |
{ start: 5, end: 10} | { start: 0, end: 10 } | true |
{ start: 5, end: 10} | { start: 0, end: 9 } | false |
Test if intervalA
and intervalB
share the same ending point.
intervalA | intervalB | result |
---|---|---|
{ start: 5, end: 10} | { start: 0, end: 10 } | true |
{ start: 5, end: 10} | { start: 5, end: 7 } | false |
Test if intervalA
is equivalent to intervalB
.
intervalA | intervalB | result |
---|---|---|
{ start: 5, end: 10} | { start: 5, end: 10 } | true |
{ start: 5, end: 10} | { start: 0, end: 10 } | false |
Test if intervalA
is adjacent to (meets) intervalB
.
intervalA | intervalB | result |
---|---|---|
{ start: 0, end: 10} | { start: 3, end: 7 } | false |
{ start: 0, end: 5} | { start: 5, end: 7 } | true |
Test if intervalA
overlaps with intervalB
.
Accept array of intervals. Intervals arrays have to be sorted.
intervalA | intervalB | result |
---|---|---|
{ start: 0, end: 10} | { start: 3, end: 7 } | true |
{ start: 0, end: 5} | { start: 5, end: 7 } | false |
{ start: 5, end: 10} | [{ start: 0, end: 4 }, { start: 7, end: 8 }] | true |
Test if intervalA
overlaps with intervalB
.
intervalA | intervalB | result |
---|---|---|
{ start: 0, end: 10} | { start: 3, end: 7 } | true |
{ start: 0, end: 5} | { start: 5, end: 7 } | false |
Test if intervalA
and intervalB
share the same starting point.
intervalA | intervalB | result |
---|---|---|
{ start: 5, end: 10} | { start: 5, end: 4 } | true |
{ start: 5, end: 10} | { start: 0, end: 10 } | false |
Merge extra properties of all intervals inside intervals
, when overlapping, with provided function mergeFn
.
Can also be used to generate an array of intervals without overlaps
Doesn't mutate input. Output keeps input's structure. Interval array has to be sorted.
parameter | value |
---|---|
mergeFn | (a, b) => {...a, data: a.data + b.data } |
intervals | [{ start: 0, end: 10, data: 5 }, { start: 4, end: 7, data: 100 }] |
result | [{ start: 0, end: 4, data: 5 }, { start: 4, end: 7, data: 105 }, { start: 7, end: 10, data: 5 }] |
Simplification of intervals
. Unify touching or overlapping intervals.
Intervals array has to be sorted.
Doesn't mutate input. Output keeps input's structure.
intervals A | result |
---|---|
[{ start: 3, end: 9 }, { start: 9, end: 13 }, { start: 11, end: 14 }] | [{ start: 3, end: 14 }] |
Split intervals
with splitIndexes
.
Keeps extra object properties on intervals
.
Doesn't mutate input. Output keeps input's structure.
splitIndexes | interval(s) | result |
---|---|---|
[2, 4] | { start: 0, end: 6, foo: 'bar' } | [{ start: 0, end: 2, foo: 'bar' }, { start: 2, end: 4, foo: 'bar' } { start: 4, end: 6, foo: 'bar' }] |
[5] | [{ start: 0, end: 7 }, { start: 3, end: 8 }] | [{ start: 0, end: 5 }, { start: 5, end: 7 }, { start: 3, end: 5 }, { start: 5, end: 8 }] |
Subtact base
with mask
.
Keeps extra object properties on base
.
Accept array of intervals. Doesn't mutate input. Output keeps input's structure. Intervals arrays have to be sorted.
interval(s) base | interval(s) mask | result |
---|---|---|
[{ start: 0, end: 4 }] | [{ start: 3, end: 7 }] | [{ start: 0, end: 3 }] |
[{ start: 0, end: 4 }, { start: 8, end: 11 }] | [{ start: 2, end: 9 }, { start: 10, end: 13 }] | [{ start: 0, end: 2 }, { start: 9, end: 10 }] |
Union of intervals
.
Accept array of intervals. Doesn't mutate input. Output keeps input's structure. Intervals arrays have to be sorted.
interval(s) A | interval(s) B | result |
---|---|---|
[{ start: 0, end: 4}] | [{ start: 3, end: 7 }, { start: 9, end: 11 }] | [{ start: 0, end: 7 }, { start: 9, end: 11 }] |
Generated using TypeDoc
Complement of
intervals
bounded toboundaries
. Convert space between two consecutive intervals into interval. Keeps extra object properties onboundaries
. intervals array has to be sorted. Doesn't mutate input. Output keeps input's structure.arg1: interval defining boundaries for the complement computation.
arg2: array of intervals that complement the result.
array of intervals.