I see there's too many questions like this , but I did not find answer for my specific case
I need all the possible combinations for my input arrays
example
if we assume the input is [1,2];
the output should be : ["11","12","21","22"]
after research , I reached to this code
function perm(xs) {
let ret = [];
for (let i = 0; i < xs.length; i = i + 1) {
let rest = perm(xs.slice(0, i).concat(xs.slice(i + 1)));
if(!rest.length) {
ret.push([xs[i]])
} else {
for(let j = 0; j < rest.length; j = j + 1) {
ret.push([xs[i]].concat(rest[j]).join(""))
}
}
}
return ret;
}
it finds most of the combinations , but not all
the above code return only ["12","21"] for input [1,2]
however all the possible combinations should be > ["11","12","21","22"]
another example for input [1,2,3] , should have this output
["111","112","121","211","113","131","311","123","321","312","213","132" , "223" , "331" , "313" , "232" .. and so on