Basic JavaScript - Replace Loops using Recursion

I’m not understanding [quote=“mcmichaeltyler93, post:3, topic:555703”]
multiply(arr, n - 1) * arr[n - 1]
[/quote]

Could you please actually answer if this explanation makes any sense.

But N is the input that is being passed in… :frowning_face:

Yes, it does. I just don’t know how one got to that conclusion.

You aren’t being asked to reinvent math here. I’m trying to get you to agree that multiply([2, 3, 1, 3, 4], 4) === 18 === 6 * 3 === multiply([2, 3, 1, 3, 4], 3) * [2, 3, 1, 3, 4][3].

The entire idea behind recursion is to make a ‘smaller’ version of the problem that takes less work to solve. To do that, you need a way to make the answer with the result of a function call with ‘smaller’ inputs.

2 * 3 === 6 * 1 === 6 * 3 === 18 * 4 === 72. Or would it be 2 * 3 * 1 * 3 since there is 3 after the comma?

I am not sure where those numbers are coming from? You are using = in between expressions that are not the same.

multiply([2, 3, 1, 3, 4], 3)

These values are not equivalent. 6 is not the same thing as 72.

The value of this expression is not 72. Also, it really helps if you use words instead of copy-pasting code at me.

OMG i get it!!! :smiley:

Thanks for being patient with me (: I always get it eventually :laughing:

1 Like

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