Hey - thanks for breaking this down. It helped me understand more clearly how the function is working. Do you have clarity on why if ( n <= 0) returns 0, as opposed to returning 1 like in the multiply function that was provided as a description for this challenge? The “hint” says " sum returns the answer, 0 - the sum of elements from 0 to 0 inclusive." I’m not sure I totally understand. Do you?
Because when you call the function as sum([1,2,3], 0) then you want to return 0 because you aren’t summing any of the numbers. If it returned 1 then the function would always return 1 more than the sum of the first n numbers because you are always adding the extra 1 for the base case.
The reason the multiply function returns 1 in the base case is because if it returned 0 then the function would always return 0 since anything multiplied by 0 is 0. So it returns 1 instead which is harmless since 1 multiplied by any number is that number. Granted, this means if you called it as multiply([1,2,3], 0) you get 1 which doesn’t necessarily make sense, but that’s the way it has to be for the recursion to work.