MCPcopy
hub / github.com/alsotang/node-lessons / fibonacci

Function fibonacci

lesson6/main.js:1–19  ·  view source on GitHub ↗
(n)

Source from the content-addressed store, hash-verified

1var fibonacci = function (n) {
2 if (typeof n !== 'number') {
3 throw new Error('n should be a Number');
4 }
5 if (n < 0) {
6 throw new Error('n should >= 0')
7 }
8 if (n > 10) {
9 throw new Error('n should <= 10');
10 }
11 if (n === 0) {
12 return 0;
13 }
14 if (n === 1) {
15 return 1;
16 }
17
18 return fibonacci(n-1) + fibonacci(n-2);
19};
20
21exports.fibonacci = fibonacci;
22

Callers 1

main.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected