-
Notifications
You must be signed in to change notification settings - Fork 0
/
server-tout.js
62 lines (43 loc) · 1.1 KB
/
server-tout.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
var express = require('express');
var path = require('path');
var port = 3000;
var app = express();
var count = 0;
var start = Date.now();
app.use(function (req, res, next) {
console.log(req.url);
count++;
// setTimeout(function () {
var end = Date.now();
console.log('time elapsed: ' + (end - start));
console.log("hit #" + count);
var k = 36;
console.log(format(firstkfib(k)));
next();
//}, 2000);
});
//calculation
app.use(express.static(path.join(__dirname, '/public'))); // The Express routes handler.
var server = app.listen(port);
server.timeout = 10000;
var fibonacci = function (n) {
if (n < 1) { return 0; }
else if (n == 1 || n == 2) { return 1; }
else if (n > 2) { return fibonacci(n - 1) + fibonacci(n - 2); }
};
//put in array
var firstkfib = function (k) {
var i;
var arr = [];
for (i = 1; i <= k; i++) {
arr.push(fibonacci(i));
}
return arr
};
//print
var format = function (arr) {
return arr.join(",");
};
//var k = 42;
//console.log("firstkfib(" + k + ")");
//console.log(format(firstkfib(k)));