How would you get all possible combinations of an array of numerical values similar to python itertools without using itertools npm package in this same order?
This is a python implementation.
from itertools import combinations
input = [0,1,2,3]
output = sum([list(map(list, combinations(input, i))) for i in range(len(input) + 1)], [])
>>> output
[[],
[0],
[1],
[2],
[3],
[0, 1],
[0, 2],
[0, 3],
[1, 2],
[1, 3],
[2, 3],
[0, 1, 2],
[0, 1, 3],
[0, 2, 3],
[1, 2, 3],
[0, 1, 2, 3]]
[value,...set]to be[...set,value]then it also preserves order. If you take that answer and apply the patch described in the comment, then order is preserved and you will get exactly the output you gave in your example.getAllSubsets([0, 1, 2, 3]).sort((a, b) => a.length - b.length || String(a).localeCompare(String(b)))