title: Optimal Javascript algorithm for finding time-based events
body: <p>I have an array of objects in Javascript, which contain an event start and end moment as milliseconds. Our codebase currently uses a naive search algorithm that iterates through the array until we find an event that contains a moment in time:</p>
  
  <pre><code>// time contains the moment of time we're looking to find an event for
  
  profile.tempbasaltreatments.forEach( function eachTreatment (t) {
      if (time &lt;= t.endmills &amp;&amp; time &gt;= t.mills) {
        return t;
      }
  });
  </code></pre>
  
  <p>which doesn't cut it with the performance with larger datasets. What'd be a good algorithm / data model to efficiently go through the object array to find an event that encapsulates a moment in time? You can assume that in case the events overlap, first match is always sufficient.</p>