I ported this method from Java to Javascript. With an "original" array with 9 objects in it, the Java code made 3000 subarrays of size 4.
In this javascript code I get 6 subarrays of size 9.
var hitterArray = new Array();
function permute(level, permuted, used, original){
if (level == 4) {
hitterArray.push(permuted); //array of arrays
} else {
for (i = 0; i < original.length; i++) {
if (!used[i]) {
used[i] = true;
permuted.push(original[i]);
permute(level + 1, permuted, used, original);
used[i] = false;
}
}
}
}
I want 3000 subarrays of size 4, why is that not working?
This is how I initialize the permute function:
var used = new Array(results.length);
for(p = 0; p < used.length; p++){
used[p] = false;
}
var permuteArray = new Array();
permute(0, permuteArray, used, results);
Insight appreciated