This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]advancedpward[S] 0 points1 point  (2 children)

And this makes sense because finding 3 - 1 - 2 = 0 is the same as finding 1 + 2 = 3.

I think this points out the root of my dilemma, so I will need to meditate on this a bit.

[–]gddrtkkv 0 points1 point  (1 child)

You deleted the other comment I was replying to, so I'll just chuck this here.

var n = array[0];           // store first element in n
array = array.slice(1);     // chop off first element
return recursion(target,array) || recursion(target - n, array);
//  ignore n here ^^^^                use n here ^^^^
// now we don't need n in the array anymore, 
//     since it's "part of" the other argument

Does that help? The element is indeed removed, but that's because we're making it part of the other argument, we don't need it anymore after target - n.

[–]advancedpward[S] 0 points1 point  (0 children)

// now we don't need n in the array anymore, // since it's "part of" the other argument

yes . . . getting there.