'Can some one explain the end of my fibonacci code?
I was creating fibonacci and my original return was "return (num - 1) + (num - 2)" but dont work, some one sugested to call the function "return fibonacci(num - 1) + fibonacci(num - 2)" and it worked, my question is why?
Code in anex
function fibonacci(num) {
if (num < 2) {
return num;
} else {
return fibonacci(num - 1) + fibonacci(num - 2)
}
}
Solution 1:[1]
I see in the MDN, "The act of a function calling itself, recursion is used to solve problems that contain smaller sub-problems. A recursive function can receive two inputs: a base case (ends recursion) or a recursive case (resumes recursion)." Thanks for the pacience to explain Parag Diwan.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Pawlick |
