I\'m trying to write a function that does the following:
Quite late. Still just in case if this helps anyone.
function permute(arr) { if (arr.length == 1) return arr let res = arr.map((d, i) => permute([...arr.slice(0, i),...arr.slice(i + 1)]) .map(v => [d,v].join(''))).flat() return res } console.log(permute([1,2,3,4]))