MCPcopy Create free account
hub / github.com/alsotang/node-lessons / fibonacci

Function fibonacci

lesson8/app.js:3–21  ·  view source on GitHub ↗
(n)

Source from the content-addressed store, hash-verified

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

Callers 1

app.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected