title: Permutation Javascript
body: <p>So I have this code now, and in input I have in ascending order my name's letters "ahimrsu". I need to show up the right number for "mariush" from all combinations which should to be 2170. For now it only show ahimrsu, ahimrus, ahimsru, ahimsur, ahimurs, ahimusr, ahirmus, ahirmsu.... etc How can I do this?</p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt;
  
  &lt;html&gt;
  &lt;head&gt;
  &lt;!--Script Function Start Here--&gt;
  &lt;script type="text/javascript"&gt;
          function perms(data) {
      if (!(data instanceof Array)) {
          throw new TypeError("input data must be an Array");
      }
  
      data = data.slice();  // make a copy
      var permutations = [],
          stack = [];
  
      function doPerm() {
          if (data.length == 0) {
              permutations.push(stack.slice());
          }
          for (var i = 0; i &lt; data.length; i++) {
              var x = data.splice(i, 1);
              stack.push(x);
              doPerm();
              stack.pop();
              data.splice(i, 0, x);
          }
      }
  
      doPerm();
      return permutations;
  }
  
  var input = "ahimrsu".split('');
  var result = perms(input);
  for (var i = 0; i &lt; result.length; i++) {
      result[i] = result[i].join('');
  }
  console.log(result);
  &lt;/script&gt;
  &lt;!--Header start here--&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;!--Script Result--&gt;
  &lt;script type="text/javascript"&gt;
          document.write(result);
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>