title: Split array into overlapping chunks (moving subgroups)
body: <p>There is a great question on how to <a href="https://stackoverflow.com/questions/8495687/split-array-into-chunks">split a JavaScript array into chunks</a>.  I'm currently using this for some statistical methods I'm writing and the <a href="https://stackoverflow.com/a/10456644/984239">answer that I'm using</a> is as follows (although I chose not to extend the Array prototype like they did in the answer):</p>
  
  <pre><code>var chunk = function(array, chunkSize) {
      return [].concat.apply([],
          array.map(function(elem,i) {
              return i%chunkSize ? [] : [array.slice(i,i+chunkSize)];
          })
      );
  };
  </code></pre>
  
  <p>This takes an array, such as <code>[1,2,3,4,5,6]</code>, and given a <code>chunkSize</code> of 2 returns <code>[[1,2],[3,4],[5,6]]</code>.  I'm curious how I could modify this to create an array of "overlapping" chunks (or for those familiar with methods such as a moving average, "moving subgroups").  </p>
  
  <p>Provided the same array as above and <code>chunkSize</code> of 3, it would return <code>[[1,2,3],[2,3,4],[3,4,5],[4,5,6]]</code>.  A <code>chunkSize</code> of 2 would return <code>[[1,2],[2,3],[3,4],[4,5],[5,6]]</code>.</p>
  
  <p>Any thoughts on how to approach this?</p>