# Subsets

Given a set of distinct integers, nums, return all possible subsets (the power set).
Note: The solution set must not contain duplicate subsets.

``````var subsets = function(nums) {
//add one more digit to each of existing, add that set to existing
const fixLength=arr.length;
//arr.push([num]);
for (let i=0;i<fixLength;i++) {
arr.push(arr[i].concat(num));
}
//no return
}
let arr=[];
arr.push([]);
for (let i=0;i<nums.length;i++) {
//send each element and append
//console.log(i,arr);
}
return arr;
};``````

Approaches:
The strategy here is to look for patterns in what we’re doing.
For each number available, we add a digit as a stand-alone set and that same digit to all other sets.

Code Breakdown:

``````    //add one more digit to each of existing, add that set to existing
const fixLength=arr.length;
//arr.push([num]);
for (let i=0;i<fixLength;i++) {
arr.push(arr[i].concat(num));
}
//no return
}``````

This is a helper function. For given array and a number, it will add that number to each of the existing elements in array argument.
For example, if the array contained:

```Array:
[]


[1,2]

Input:
3

Result is original array PLUS:
 <- adding 3 to []
[1,3] <- adding 3 to 
[2,3] <- adding 3 to 
[1,2,3] <- adding 3 to [1,2]```
``````    let arr=[];
arr.push([]);
for (let i=0;i<nums.length;i++) {
//send each element and append