function powerSet(arr) {
let check = new Array(arr.length).fill(0);
console.log(check)
let powerSetArr = [];
const dfs = (depth) => {
if (depth === check.length) {
powerSetArr.push(arr.filter((v, idx) => check[idx]));
}
else {
check[depth] = 1;
dfs(depth + 1);
check[depth] = 0;
dfs(depth + 1);
}
};
dfs(0);
console.log(powerSetArr)
return powerSetArr.sort();
}
let a = powerSet([1,2,3])
const subsets = (nums) => {
const res = [];
const dfs = (start = 0, arr = []) => {
res.push(arr);
for (let i = start; i < nums.length; i++) {
dfs(i + 1, [...arr, nums[i]]);
}
};
dfs();
return res;
};
let b = subsets([1,2,3])