range-overlaps
Version:
Checks whether two ranges/intervals overlap. Returns true or false.
27 lines (19 loc) • 795 B
Markdown
# Range-Overlaps - check whether two intervals overlap #
Checks whether two numeric ranges overlap. For example, [0, 3] and [1, 6] do
overlap, while [0, 3] and [4, 6] do not overlap.
## Usage ##
`rangeOverlaps(range1, range2, exclusive = false)`
The first two arguments are two intervals, each of which is an object with the
`start` and `end` fields:
```
const rangeOverlaps = require('range-overlaps');
// Prints `true`:
console.log(
rangeOverlaps({start: 0, end: 3}, {start: 1, end: 6})
);
```
### Options ###
The third argument is a boolean value that indicates whether an exclusive search
should be performed. For example, [0, 3] and [3, 6] would normally be considered
overlapping. With exclusive search (`true`), these will not be considered
overlapping.