permutations without recursion

permutations without recursion http://stackoverflow.com/questions/34013675/permutations-without-recursive-function-call http://www.quickperm.org/03example.php

JavaScript

var str = "123";
var perm = 1, digits = str.length;
for (var i = 1;i<digits.length;perm*=i++);
for (var j = 0;j < perm; j++) {
  var avail = str;
  for (var b = digits, div = perm; b>0; b--) {
    div/=b;
    var index = (j/div)%b;
    console.log(avail[index]);
    // avail[index]=avail[b-1]; // non-lexigraphic but fast
    // avail.erase(index,1) ; // lexigraphically correct
    avail = avail.slice(index, 1)
  }
}