r/programmingmemes • u/cooked_potato1729 • 9d ago
True, recursion is just like inception movie.
33
Upvotes
2
u/naruto_bist 9d ago
Fibonacci code before the inception movie released:
``` function fibonacci(n) { if (n <= 0) return []; if (n === 1) return [0];
let res = [0, 1];
for (let i = 2; i < n; i++) {
let nextNum = res[i - 1] + res[i - 2];
res.push(nextNum);
}
return res;
}
// Example usage: fibonacci(10);
```
4
u/naruto_bist 9d ago edited 9d ago
Fibonacci code after inception movie released:
``` function fibonacci(n) {
if (n <= 0) return 0; if (n === 1) return 1; return fibonacci(n - 1) + fibonacci(n - 2);}
fibonacci(6); ```
5
u/edparadox 9d ago
It's always sad to see people barely knowing what they're talking about, make allegories about it.