const shred = arr => arr.reduce((p,c,i,a) => {
const f = prefix => {
for (let j=0; j<a.length; j++)
if (prefix.length < a.length - 1) {
f(prefix + a[j]);
} else {
p.push(+(prefix + a[j]));
}
}
f(c.toString());
return p;
}, []);
shred([1,2,3]);
/*
[111,112,113,121,122,123,131,132,133,211,212,213,221,222,223,231,232,233,311,312,313,321,322,323,331,332,333]
*/
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]))
}
}
}
return ret;
}
console.log(perm([1,2,3]).join("\n"));
for(i = 1; i < 4; i++){
for(j = 1; j < 4; j++){
for(g = 1; g < 4; g++){
console.log(""+i+j+g);
}
}
}