# Replace Loops using Recursion -1 explanation

**URL:** <https://forum.freecodecamp.org/t/replace-loops-using-recursion-1-explanation/368021>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [April 4, 2020, 12:21pm UTC](https://forum.freecodecamp.org/t/replace-loops-using-recursion-1-explanation/368021 "2020-04-04T12:21:38Z")\
**Posts on this page:** 1\
**Showing post:** 38

<div class="post-metadata">

**Author:** ![JeremyLT](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jeremylt/32/291894_2.png) [@JeremyLT](https://forum.freecodecamp.org/u/JeremyLT)\
**Post date:** [April 8, 2020, 3:32pm UTC](https://forum.freecodecamp.org/t/replace-loops-using-recursion-1-explanation/368021/38 "2020-04-08T15:32:14Z")

</div>

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.

---

_[View the full topic](https://forum.freecodecamp.org/t/replace-loops-using-recursion-1-explanation/368021)._
