var subsets = function (nums) {
let index = 0;
let subset = [];
let tempArray = [];
findSubset(index, nums, subset, tempArray);
return subset;
};
const findSubset = (index, nums, subset, tempArray) => {
if (index >= nums.length) {
subset.push([...tempArray]);
return;
}
findSubset(index + 1, nums, subset, tempArray);
tempArray.push(nums[index]);
findSubset(index + 1, nums, subset, tempArray);
tempArray.pop();
};
console.log(subsets([1, 2, 3]));
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)