To complement Gareth answer.
For anyone needing to perform more complex types of overlap checking in intervals,
there is a nice data structure called Interval Tree.
https://en.wikipedia.org/wiki/Interval_tree
tree data structure to hold intervals. Specifically, it allows one to efficiently find all intervals that overlap with any given interval or point.
Example taken from this javascript implementation
let tree = new IntervalTree();
let intervals = [[6,8],[1,4],[5,12],[1,1],[5,7]];
// Insert interval as a key and string "val0", "val1" etc. as a value
for (let i=0; i < intervals.length; i++) {
tree.insert(intervals[i],"val"+i);
}
// Get array of keys sorted in ascendant order
let sorted_intervals = tree.keys; // expected array [[1,1],[1,4],[5,7],[5,12],[6,8]]
// Search items which keys intersect with given interval, and return array of values
let values_in_range = tree.search([2,3]) // expected array ['val1']