I'm currently a bit befuddled... I'm tasked with finding the value of x, is this an example of recursion? I am not asking for a straight answer for the value of x, I can find that out with some guidance from the Overflow community. I get confused at a = b, and b = t, then where is says return the function.
Any and all help is greatly appreciated!
function f(a, b, c) {
if (c > 1) {
c = c - 1;
var t = a + b;
a = b;
b = t;
return f(a, b, c);
}
return a + b;
}
var x = f(1, 3, 4);
Yes, this line here: return f(a, b, c) - this is recursion as it is calling itself at the end. It's modifying the parameters that it receives and re-calling itself again.
Yes, this is an example of recursion. You can tell this because function f() calls function f() (itself) with a smaller subset on line 7.
You might find this documentation from Microsoft helpful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With