This says:
multiplying the first n elements of arr is the same as taking the product of the first n-1 elements of arr and multiplying that by the nth element of arr
My apologies. I’ve edited my post and know better for next time. As for your answer, I’m still a little thrown off. How do they equal each other if one is seemingly more steps than the other? Where do those -1’s come from and why are there square brackets around the second n -1?
So typing multiply(arr, n) is exactly like typing out multiply(arr, n - 1)* arr [n-1]
Am I interpreting that incorrectly?
btw, sorry if these questions seem dumb or confuse you. I’ve just started coding last week. This is my first language. Was doing alright but real confused on how these equal each other.
The produce the exact same number. Let’s look at a specific case.
const arr = [1, 2, 3, 4];
const first_way = multiply(arr, 4); // This is 1*2*3*4=24
console.log(multiply(arr, 3)); // This is 1*2*3=6
console.log(multiply(arr[3])); // This is 4
const second_way = multiply(arr, 3) * arr[3]; // This is also 6*4=24
console.log(first_way === second_way); // 'true', they provide the same value
Right, got it. So using that info in my original problem,
multiply(arr, n) == multiply(arr, n - 1) * arr[n - 1]
Since the binary count starts at 0, is the example just showing that the n-1 just doesn’t exist yet?
I 100% understand your specific case so I believe I’ve grasped what is being stated.
I think I’m just overthinking it since the original problem has arr[n-1] whereas in your example you use arr[3] which is far easier to read in my opinion.
Oh yeah binary count deals with only 0’s and 1’s excuse my ignorance.
Okay I see. I was reading it way too literally. For some reason I was trying to find specifically where the -1 was coming from but am now able to see that it’s just in place to show the statement will still be true if n= 9 or n= 99999999 . You’ve been a huge help. Thank you!