Ad
Recursion
Mathematics
Code
Diff
  • function fibonacci(n) {
     return n <= 1 ? n : fibonacci(n - 1) + fibonacci(n - 2);
    }
    • function fibonacci(n) {
    • return n === 0 || n === 1 ? n : fibonacci(n - 1) + fibonacci(n - 2);
    • return n <= 1 ? n : fibonacci(n - 1) + fibonacci(n - 2);
    • }
Recursion
Mathematics
Code
Diff
  • function fibonacci(n) {
        return n <= 1 ? n : fibonacci(n - 1) + fibonacci(n - 2);
    }
    • function fibonacci(n) {
    • if (n <= 1) return n;
    • return fibonacci(n - 1) + fibonacci(n - 2);
    • return n <= 1 ? n : fibonacci(n - 1) + fibonacci(n - 2);
    • }
Recursion
Mathematics
Code
Diff
  • function fibonacci(n) {
     return n === 0 || n === 1 ? n : fibonacci(n - 1) + fibonacci(n - 2);
    }
    • function fibonacci(n) {
    • if (n === 0) return 0;
    • if (n === 1) return 1;
    • return fibonacci(n - 1) + fibonacci(n - 2);
    • return n === 0 || n === 1 ? n : fibonacci(n - 1) + fibonacci(n - 2);
    • }