var fib = function (n) {
if (n == 1) {
return [0, 1];
} else {
var s = fib(n - 1);
s.push(s[s.length - 1] + s[s.length - 2]);
return s;
}
}
console.log(fib(5));
In the above code snippet, when I do a debug - after the return s
is executed first time control goes back to s.push(s[s.length - 1] + s[s.length - 2]);
.
My understanding is that "return" should be the last statement executed in a code snippet.
It will be very appreciated if someone could help me understand this.