title: Sliding window over Array in JavaScript
body: <p>I need a sliding window over an Array in JavaScript.</p>
  <p>For example, a sliding window of size <code>3</code> over <code>[1,2,3,4,5,6,7,8,9]</code> shall compute the sequence <code>[[1,2,3],[2,3,4],[3,4,5],[4,5,6],[5,6,7],[6,7,8],[7,8,9]]</code>.</p>
  <p>The following is my attempt, because I couldn't find a readymade solution:</p>
  <pre><code>function window(a, sz) {
    return a.map((_, i, ary) =&gt; ary.slice(i, i + sz)).slice(0, -sz + 1);
  }
  </code></pre>
  <p>It returns an array of windows that can be mapped over to get the individual windows.</p>
  <p>What is a better solution?</p>