Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const subsetsWithDup = (arr) => {
- // sorting makes sure we have the most unique vectors
- // i.e. [2,1,2] === [1,2,2] (same)
- arr = arr.sort();
- return helper(arr);
- }
- const helper = (arr, index = 0, slate = [], results = [], set = new Set()) => {
- results.push(slate);
- if (index === arr.length)
- return;
- for (let i = index; i < arr.length; i++) {
- if(i != index && arr[i] == arr[i-1])
- continue;
- helper(arr, i + 1, [...slate, arr[i]], results, set);
- }
- return results;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement