title: Permutations in JavaScript?
body: <p>I'm trying to write a function that does the following:</p>
  <ul>
  <li>takes an array of integers as an argument (e.g. [1,2,3,4])</li>
  <li>creates an array of all the possible permutations of [1,2,3,4], with each permutation having a length of 4</li>
  </ul>
  <p>the function below (I found it online) does this by taking a string as an argument, and returning all the permutations of that string</p>
  <p>I could not figure out how to modify it to make it work with an array of integers, (I think this has something to do with how some of the methods work differently on strings than they do on integers, but I'm not sure...)</p>
  <pre><code>let permArr = [];
  let usedChars = [];
  
  function permute(input) {
      const chars = input.split(&quot;&quot;);
      for (let i = 0; i &lt; chars.length; i++) {
          const ch = chars.splice(i, 1);
          usedChars.push(ch);
          if (chars.length === 0) {
              permArr[permArr.length] = usedChars.join(&quot;&quot;);
          }
          permute(chars.join(&quot;&quot;));
          chars.splice(i, 0, ch);
          usedChars.pop();
      }
      return permArr
  };
  </code></pre>
  <p>Note: I'm looking to make the function return arrays of <em>integers</em>, <strong>not</strong> an array of <em>strings</em>.</p>
  <p>I really need the solution to be in JavaScript. I've already figured out how to do this in python</p>