I search something about recursionl, in particular Fibonacci sequence and I see this example:
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]);
console.log(s[s.length -1]); // add me
console.log(s[s.length -2]); // add me
return s;
}
};
console.log(fibonacci_series(8));
and I don’t understand what means s[s.length -1]
and s[s.length-2]
, I mean they represent the positions or other things.
If it presents the positions which one does it take?
Or there’s something that escapes me and I can’t see.
P.S
I ask if there is any resource that explains it in a simple step by step manner.
Thanks,
CamCode