If I have a given array of digits, eg:
[1, 2, 7, 1, 9]
How can I recursively create an array of all possible combinations of these digits, eg:
[12719, 12791, 12971, 12179, etc...]
I would like to accomplish this with something like:
const producePossibleNumbers = (digits) => {
    return digits.map((d, index) => {
        const remainingDigits = digits.filter((x, i) => i !== index)
        if (remainingDigits.length === 1) {
            return d + remainingDigits[0]
        } else {
            producePossibleNumbers(remainingDigits)
        }
    })    
}
Obviously this is complete / non-functional code... Need a jump start.
 
    