title: javascript permutation generator with permutation length parameter
body: <p>I've seen a few generators out there but they all make a squared matrix. For example, you give it a list of three items and it'll assume the output of the length is also three. However, I'd like to specify the items and the length. </p>
  
  <p>Sound like an easy problem can't believe there isn't a library available for it. Would like to avoid writing this myself if there's a tested library out there. Any suggestions would be great.</p>
  
  <p>Example of what i've found</p>
  
  <pre><code>var list = 'abc';
  perms = permutations(list);
  //you cannot define the length
  </code></pre>
  
  <p>Example</p>
  
  <pre><code>var list = 'abc';
  var length = 3;
  
  perms = permutations(list,length);
  
  console.log(perms);
  
  /* output
  a,a,a
  a,b,c
  a,b,a
  a,c,a
  c,a,a
  ...
  */
  </code></pre>
  
  <p>I would like to be able to change length and should create permutations accordingly</p>
  
  <pre><code>length = 2
  
  a,a
  a,b
  b,b
  b,a
  
  length = 4
  
  a,a,a,a 
  a,a,a,b
  ....
  </code></pre>