title: Group array Elements in a sequence JavaScript
body: <p>I am trying to group weekdays together based on the property value in an array. I have used lodash to obtain a solution. My code looks like this,</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const array = [{
      weekDay: 'Monday',
      hoursInfo: '11:00am-8:00pm',
    },
    {
      weekDay: 'Tuesday',
      hoursInfo: '11:00am-8:00pm',
    },
    {
      weekDay: 'Wednesday',
      hoursInfo: '9:00am-11:00am',
    },
    {
      weekDay: 'Thursday',
      hoursInfo: '11:00am-8:00pm',
    },
    {
      weekDay: 'Friday',
      hoursInfo: '11:00am-9:00pm',
    },
    {
      weekDay: 'Saturday',
      hoursInfo: '11:00am-9:00pm',
    },
    {
      weekDay: 'Sunday',
      hoursInfo: 'Closed',
    },
  ];
  const result = _.chain(array).groupBy("hoursInfo").value();
  document.getElementById("result").innerHTML = JSON.stringify(result);</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js"&gt;&lt;/script&gt;
  &lt;div id="result"&gt;&lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>I am able to group the list of weekdays which has the same timings together, but my requirement is to group them in a sequence. My expected output is something like this,</p>
  <pre><code>Monday-Tuesday: 11:00am-8:00pm
  Wedesday: 9:00am-11:00am
  Thursday: 11:00am-8:00pm
  Friday-Saturday: 11:00am-9:00pm
  Sunday: Closed
  </code></pre>
  <p>Please help me with a better approach</p>