I am having a brain lapse in recursion and trying to get the math right. The function gives me what I want but my brain does not.
let recurseSum = (x, n) => {
if(n === 1){ return x}
return x + recurseSum(x, n-1)
}
log = console.log
log(recurseSum(3, 2))
How is this broken down again, the answer and what I write is not right.
3 + recurse(3, (2-1) = 3 + 1 = 4
3 + resurse(3, (1-1) = 3....ggrrrrrrr
How do I write this out properly.
2
Answers
Per the comments I have answered my own question
Just add some logging to see how it actually behaves, no need to type this stuff out manually