title: Subset sum - get array indices instead of values
body: <p>I have the following function:</p>
  
  <pre><code>function createSubsets(numbers, target) {
    // filter out all items larger than target
    numbers = numbers.filter(function (value) {
      return value &lt;= target;
    });
  
    // sort from largest to smallest
    numbers.sort(function (a, b) {
      return b - a;
    });
  
    // array with all the subsets
    var result = [];
  
    while (numbers.length &gt; 0) {
      var i;
      var sum = 0;
      var addedIndices = [];
  
      // go from the largest to the smallest number and
      // add as many of them as long as the sum isn't above target
      for (i = 0; i &lt; numbers.length; i++) {
        if (sum + numbers[i] &lt;= target) {
          sum += numbers[i];
          addedIndices.push(i);
        }
      }
      console.log(addedIndices);
      // remove the items we summed up from the numbers array, and store the items to result
      // since we're going to splice the numbers array several times we start with the largest index
      // and go to the smallest to not affect index position with splice.
      var subset = [];
      for (i = addedIndices.length - 1; i &gt;= 0; i--) {
        subset.unshift(numbers[addedIndices[i]]);
        numbers.splice(addedIndices[i], 1);
      }
      result.push(subset);
    }
    return result;
  }
  </code></pre>
  
  <p>This basically gets an array and it returns the subsets that sum up to <code>target</code>. Is it possible to change this function to return the subset indices (of the original <code>number</code> array) that sum up to target?</p>