Recursion and return

n is representing the first n items. Think about it in terms of array indexes.

What is the index of the first array item, it is 0. Ok so what number is located at index arr[0]? It is 2. There’s nothing else to sum it with because the second parameter was 1. So it just returns 2 in that case.

For sum([2, 3, 4, 5], 3)

we are to sum the first three items. That is what the three means there. We are not adding it in.

How would we programmatically access the first 3 items in an array? By their indexes, right? So what are the indexes? 0, 1, 2 respectively.

arr[0] is 2
arr[1] is 3
arr[2] is 4

those are the first 3 items. What is their sum? 9

This link has a more detailed explanation…

spoiler alert…