title: How to count time elapsed between two items in array of objects?
body: <p>I have an array of objects like this:</p>
  <pre><code>events: 
   [{
     eventInfo: &quot;START_event1&quot;,
     timeStamp: &quot;2020-11-29T22:01:53.634041+00:00&quot;
    },
    {
     eventInfo: &quot;END_event1&quot;,
     timeStamp: &quot;2020-11-29T22:04:00.634041+00:00&quot;
    },
    {
     eventInfo: &quot;START_event1&quot;,
     timeStamp: &quot;2020-11-29T23:00:00.634041+00:00&quot;
    },
    {
     eventInfo: &quot;START_event2&quot;,
     timeStamp: &quot;2020-11-29T23:01:53.634041+00:00&quot;
    },
    {
     eventInfo: &quot;END_event1&quot;,
     timeStamp: &quot;2020-11-29T23:04:50.634041+00:00&quot;
    },
    {
     eventInfo: &quot;END_event2&quot;,
     timeStamp: &quot;2020-11-29T23:24:00.634041+00:00&quot;
    }]
  </code></pre>
  <p>The array will have multiple occurrences of an event with a same name. I am supposed to calculate the total time elapsed with event1, event2 and so on.</p>
  <p>The issue is that there is no other way of knowing which event starts and endings are a pair other than the eventInfo string having start or end in the name. For example the consequent START_event1 and END_event1 are supposed to be a pair and so is the START_event2 and END_event2 (even though there is another START_event1 in between of them).</p>
  <p>The end result I'm looking for is a new array where there are total run times for each event name.</p>
  <pre><code>[{
  event1: totalRuntime
  },
  {
  event2: totalRuntime
  },
  {
  eventN: totalRuntime
  }]
  </code></pre>