MCPcopy Create free account
hub / github.com/appacademy/Module-1-Resources / fibonacci

Function fibonacci

w3/d2/eod.js:91–97  ·  view source on GitHub ↗

Write a recursive function called `fibonacci` that takes an integer, `n`, and returns the `n`th number in the Fibonacci sequence. Not familiar with the Fibonacci sequence? Beginning with 0 and 1, we add the two previous numbers in the sequence together to form the next one: 0, 1, 1, 2, 3, 5, 8, et

(n)

Source from the content-addressed store, hash-verified

89***********************************************************************/
90
91function fibonacci(n){
92
93 if (n === 1 || n === 2) return 1;
94
95 return fibonacci(n - 1) + fibonacci(n - 2)
96
97}
98
99
100// console.log(fibonacci(1)); // 1

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected