Interval tree implementation in JavaScript