I'm working through Coderbyte's array addition problem:
Using the JavaScript language, have the function
ArrayAdditionI(arr)take the array of numbers stored inarrand return the string true if any combination of numbers in the array can be added up to equal the largest number in the array, otherwise return the string false. For example: ifarrcontains[4, 6, 23, 10, 1, 3]the output should return true because4 + 6 + 10 + 3 = 23. The array will not be empty, will not contain all the same elements, and may contain negative numbers.
I've come up with the solution below, but for some reason, cannot get the recursion to work. The code correctly identifies arrays where the remaining (non-largest) array elements exactly add up to the largest, but fail otherwise. Any suggestions?
function ArrayAdditionI(arr) { 
  arr = arr.sort(function(a,b) {return b-a});
  match = false;
  largest = arr.shift(arr[0]); 
  function test(a){
    if(eval(a.join("+"))==largest){
      match = true;
      return match}
    else {
      for(i = 0; i < a.length; i++){
        newArr = a.slice();
        newArr.splice(i,1);
        return test(newArr);
      }
    }
  }
  test(arr);
  return match;
}

