Finding recursion hard

Tell us what’s happening:

  **Your code so far**

Hi All

I’m struggling to get to grips with recursions. I can get some grip on the ide but on the actually exercise I really don’t get how (arr, n) == (arr, n --1)*arr[n-1].

The idea is to multiply all the elements in the array given by n together.
If n was say 3, then this would be (3-1)*(3-1) = 4. Or 9 if n = 4, or 16 if n = 5.

  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36 Edg/89.0.774.57.

Challenge: Replace Loops using Recursion

Link to the challenge:

you are missing the function
the point is that in one case the function multiply the first n elements of the array together, in the second one it multiply the first n-1 elements, and then the nth is multiplied to that result, both gives the same result

recursion is calling the function inside itself but with a smaller argument
you can calculate the product of the first n elements in an array if you first get the product of the first n-1 element and then multiply to it the nth

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.