title: Quick and efficient permutations with max length
body: <p>I want to make a permutation function in javascript that very quickly finds all permutations of an array, with every length before it (I'll give an example explaining this further). It needs to be as quick and efficient as possible, and should not have any duplicates. For example, the function would take an input of a list which would be like </p>
  
  <pre><code>[0, 1, 2]
  
  </code></pre>
  
  <p>and the expected output would be</p>
  
  <pre><code>[[0], [1], [2], [0, 1], [0, 2], [1, 2], [1, 2, 3]]
  </code></pre>
  
  <p>There wouldn't be any duplicates in the array (like [0, 0] wouldn't work), and swapped values shouldn't be there either ([1, 0] and [0, 1] both wouldn't be there. Only one of them). </p>
  
  <p>I've looked at <a href="https://stackoverflow.com/questions/23305747/javascript-permutation-generator-with-permutation-length-parameter">this question</a> and <a href="https://stackoverflow.com/questions/9960908/permutations-in-javascript">this question</a> but am still unable to get what I wanted. </p>
  
  <p><strong>The most important thing is that this needs to be as efficient as possible (take as little time to execute as possible)</strong></p>