So I created the fibonacci series, but the way I found on w3resources is a bit confusing to me as a beginner. What exactly happens when n = 2
? s
becomes fibonnacci_series(1)
, but what does this even imply? In the first place why do we have var fibonacci_series = function(n)
, why not just have a function called function fibonacci_series(n)
?
var fibonacci_series = function (n)
{
if (n===1)
{
return [0, 1];
}
else
{
var s = fibonacci_series(n - 1);
s.push(s[s.length - 1] + s[s.length - 2]);
return s;
}
};
console.log(fibonacci_series(8));