title: How to combine consecutive dates in javascript?
body: <p>I have an array of dates such as :</p>
  
  <pre><code>test = [ '2018-07-18', '2018-07-19', '2018-07-21', '2018-07-23', '2018-07-24', '2018-07-26'];
  </code></pre>
  
  <p>And I want to return an array of sub arrays of consecutive dates like this:</p>
  
  <pre><code>result = [['2018-07-18', '2018-07-19'], ['2018-07-21'], ['2018-07-23', '2018-07-24'], ['2018-07-26']]
  </code></pre>
  
  <p>I'm trying to write a snippet code:</p>
  
  <pre><code>const moment = require('moment');
  let visited = [];
  const alpha = test.reduce((accumlator, current_date, current_index, array) =&gt; {
      let start_date = current_date;
      let successive_date = array[current_index + 1];
      visited.push(start_date);
      if(successive_date &amp;&amp; moment(successive_date).diff(moment(start_date), 'days') === 1  
          &amp;&amp; visited.includes(successive_date) === false) {
          accumlator.concat(start_date);
          accumlator.concat(successive_date);
      }
      if(successive_date &amp;&amp; moment(successive_date).diff(moment(start_date), 'days') !== 1  
          &amp;&amp; visited.includes(successive_date) === false) {
          accumlator.concat(successive_date);
      }
      return accumlator;
  }, []);
  
  console.log('alpha: ', alpha);
  </code></pre>
  
  <p>The result when using <code>concat</code> was: </p>
  
  <pre><code>alpha: []
  </code></pre>
  
  <p>I used <code>push()</code> and it returns an array such <code>test</code>:</p>
  
  <pre><code>alpha:  [ '2018-07-18','2018-07-19','2018-07-21','2018-07-23','2018-07-23','2018-07-24''2018-07-26' ]
  </code></pre>
  
  <p>How can I fix this in order to get the result such as mentioned above?</p>