title: How can I get MIN and MAX intervals by a consecutive property in a Javascript Object?
body: <p>I need help to get the max and min date differences (in hours or days(float)) for each location. If the interval have only one date for that location, consider the difference from date above. The object is already sort by date(desc) and the rack is the same for all, can disregard. Thank you.</p>
  
  <pre><code>var data = [
      {rack: 1208, location: 42, date: "2020-05-11T13:53:51.000Z"},
      {rack: 1208, location: 42, date: "2020-05-08T12:36:51.000Z"},
      {rack: 1208, location: 40, date: "2020-05-08T12:36:27.000Z"},
      {rack: 1208, location: 41, date: "2020-05-08T10:44:40.000Z"},
      {rack: 1208, location: 41, date: "2020-05-08T10:43:33.000Z"},
      {rack: 1208, location: 42, date: "2020-05-08T10:42:55.000Z"},
      {rack: 1208, location: 41, date: "2020-05-08T10:41:55.000Z"},
      {rack: 1208, location: 40, date: "2020-05-08T10:41:18.000Z"},
      {rack: 1208, location: 40, date: "2020-05-08T09:47:42.000Z"},
      {rack: 1208, location: 40, date: "2020-05-07T10:24:56.000Z"}
  ]
  
  var response = {
      42: {
          minHours : {
              value: 0.01,
            startTime: '2020-05-08T10:42:55.000Z',
            endTime: '2020-05-08T10:43:33.000Z'
          },
          maxHours : {
              value: 73.28,
            startTime: '2020-05-08T12:36:51.000Z',
            endTime: 'NOW() Current Datetime'
          }
     },
     41: {
          //do the same
     },
     40: {
          //do the same
     }
  };
  </code></pre>
  
  <p>It's like a timeline, where I have to track the "rack".</p>
  
  <p>1) From bottom to top: the rack arrived at site 40 on 2020-05-07T10: 24: 56.000Z and went to site 41 on 2020-05-08T10: 41: 55.000Z. So that rack remained 24.28 at location 40.</p>
  
  <p>2) Now the rack arrived at site 41 on 2020-05-08T10: 41: 55.000Z and soon after it went to site 42 on 2020-05-08T10: 42: 55.000Z. So the time of stay at site 41 was 1 minute or 0.016 hours.</p>
  
  <p>And so on. In the case of the first 2 lines, the rack arrived at location 42 on 2020-05-08T12: 36: 51.000Z and above it has no more locations, so it must compare with the current date and time.</p>
  
  <p>Each comparison updates maxHours and minHours for that location if the difference is greater than maxHours or less than minHours.</p>