xxxxxxxxxx
function combination(array = [], text = "") {
if (array.length !== 0) {
for (let i = 0; i < array.length; ++i) {
const newArray = array.filter((element, index) => index !== i)
text += array[i];
if (array.length === 1) {
console.log(text)
}
combination(newArray, text)
text = text.slice(0, -1)
}
}
}
const array = [1, 2, 3];
combination(array)
/*
Output:
123
132
213
231
312
321
*/