I\'m trying to create a function in JavaScript that given a string will return an array of all possible combinations of the letters with each used at most once, starting wit
You could use a nasty trick and increase a counter and use its binary representation as flags:
function combine(str){ const result = []; for(let i = 1; i < Math.pow(2, str.length) - 1; i++) result.push([...str].filter((_, pos) => (i >> pos) & 1).join("")); return result; }
Try it