KEMBAR78
Fibonacci Recrsion Javascript | PDF | Science | Teaching Mathematics
0% found this document useful (0 votes)
80 views1 page

Fibonacci Recrsion Javascript

This document defines a recursive function to calculate Fibonacci numbers, where fibonacci(n) returns the nth Fibonacci number by recursively calling itself with arguments n-1 and n-2, and base cases return 1 if n is less than 2.

Uploaded by

srobleh123
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views1 page

Fibonacci Recrsion Javascript

This document defines a recursive function to calculate Fibonacci numbers, where fibonacci(n) returns the nth Fibonacci number by recursively calling itself with arguments n-1 and n-2, and base cases return 1 if n is less than 2.

Uploaded by

srobleh123
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

// return fibonacci // n = (n-1)+(n-2)

function fibonacci(n) { if (n < 2){ return 1; }else{ return fibonacci(n-2) + fibonacci(n-1); } } console.log(fibonacci(7)); //Returns 21

You might also like