Recursive Text Iteration
by Francis MacDougall
HTML
<div id="answer">
</div>
JavaScript
var arr = [];
var index = 0;
function recursive(istr,curstr,count) {
count--;
for(var i=0; i<istr.length; i++) {
var str = curstr + istr.charAt(i);
if(count>0) {
recursive(istr,str,count);
}
else {
document.getElementById("answer").innerHTML += str + " ";
arr[index++] = str; // or they are in the array here
}
}
}
function enumerate(str, n) {
for(var i=0;i<n;i++) {
recursive(str,"",i+1);
}
}
enumerate("12345",3);
document.getElementById("answer").innerHTML += "<br>Total: " + index;