title: Find All Subsets in an array, Recursion is not working, JavaScript
body: <p>I am trying to implement Given a set of distinct integers, S, return all possible subsets problem.    </p>
  
  <p>[A, B, C] should give  [ [ ], [A], [A, B], [A, B, C], [A, C], [B], [B, C], [C] ].</p>
  
  <p>Cannot figure out why the function does not backtrack.</p>
  
  <p>For input [A, A, B, C], my implementation outputs [ [], ["A"], ["A", "A"],  ["A", "A", "B"], ["A", "A", "B", "C"] ]</p>
  
  <p>This is my code.</p>
  
  <pre><code>var subsets = function(A){
    /*for input [ A, A, B, C ], appendCount returns [ [A, 2], [B, 1], [C,1] ]*/
    var arr = appendCount(A);
    result =[[]];
    var tempArr = [];
  
    var findSubsets = function(index, tempArr, a) {
      var arrCopy = a.slice();
      while(index &lt; arrCopy.length) {
        if(arrCopy[index][1] &gt; 0) {
          tempArr.push(arrCopy[index][0]);
          result.push(tempArr.slice());
          var newArr = arrCopy.slice();
          newArr[index][1] -= 1;
          findSubsets(index, tempArr, newArr);
          tempArr.pop();
          index++;
     } else {
         index++;
     }
   } 
  }
   findSubsets(0, tempArr, arr.slice());
   return result;
  }
  </code></pre>
  
  <p>Thanks in advance</p>