MCPcopy
hub / github.com/mgechev/javascript-algorithms / fibonacci

Function fibonacci

src/others/fibonacci.js:21–37  ·  view source on GitHub ↗
(n)

Source from the content-addressed store, hash-verified

19 'use strict';
20
21 function fibonacci(n) {
22 if (n > 97) {
23 throw 'Input too large, results in inaccurate fibonacci value.';
24 }
25 var n1 = 0;
26 var n2 = 1;
27 var aux;
28
29 while (n > 0) {
30 aux = n1;
31 n1 = n2;
32 n2 += aux;
33 n = n - 1;
34 }
35
36 return n1;
37 }
38
39 exports.fibonacci = fibonacci;
40})(typeof window === 'undefined' ? module.exports : window);

Callers 2

fibonacci.spec.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected