title: Given an array, how to generate all combinations of subset size k?
body: <p>So given <code>input = [1, 2, 3]</code> and <code>k=2</code> this would return:</p>
  
  <pre><code>1 2
  1 3
  2 1
  2 3
  3 1
  3 2
  </code></pre>
  
  <p>This is the closest to what I am looking for, but not quite: <a href="http://algorithms.tutorialhorizon.com/print-all-combinations-of-subset-of-size-k-from-given-array/" rel="noreferrer">http://algorithms.tutorialhorizon.com/print-all-combinations-of-subset-of-size-k-from-given-array/</a></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>function subsetsOfSize(a, used, startIndex, currentSize, k) {
    if (currentSize === k) {
      for (var i = 0; i &lt; a.length; i++) {
        if (used[i])
          console.log(a[i]);
      }
      console.log('-');
      return;
    }
      
    if (startIndex === a.length)
      return;
      
    used[startIndex] = true;
    subsetsOfSize(a, used, startIndex+1, currentSize+1, k);
  
    used[startIndex] = false;
    subsetsOfSize(a, used, startIndex+1, currentSize, k);
  }
  
  var input = [1,2,3];
  subsetsOfSize(input, Array(input.length).fill(false), 0, 0, 2);</code></pre>
  </div>
  </div>
  </p>
  
  <p>^ Missing results such as <code>2 1</code>, <code>3 1</code>, <code>3 2</code>, etc.</p>
  
  <p>Secondly, I am not sure if I am naming this problem correctly because solutions to "all combinations of subset of size k" do not give the expected answer.</p>