Replace Loops using Recursion -1 explanation

Ok.

Let’s look at the array arr = [2, 4, 1, 5].

When I call multiply(arr, 4), I should get 2 * 4 * 1 * 5 = 40.

When I call multiply(arr, 3), I should get 2 * 4 * 1 = 8.

We can write this as
multiply(arr, 4) == 40
and
multiply(arr, 3) == 8

Note that we are using == to mean that the left and right hand side of the comparator evaluate to the same value.

Notice that
40 == 8 * 5
and that
arr[3] == 5

This means that
40 == 8 * arr[3]

We are close here.

Now we can say that
40 == multiply(arr, 3) * arr[3]

Finally, we can say that
multiply(arr, 4) == multiply(arr, 3) * arr[3]

The last thing to notice is that n = 4 so
multiply(arr, n) == multiply(arr, n - 1) * arr[n - 1]

All of this was based on the return values of these functions.