1 | var _progress = require('./main');
|
2 | var limit = 43;
|
3 |
|
4 |
|
5 |
|
6 | function fibonacci(n) {
|
7 | if (n < 2) {
|
8 | return 1;
|
9 | }else {
|
10 | return fibonacci(n - 2) + fibonacci(n - 1);
|
11 | }
|
12 | }
|
13 |
|
14 |
|
15 | var bar = new _progress.Bar({
|
16 | format: 'Fibonacci Calculation Progress [{bar}] {percentage}% | ETA: {eta}s | Current: F({value})',
|
17 | hideCursor: true
|
18 | });
|
19 | bar.start(limit, 1);
|
20 |
|
21 | var fibonacciNumbers = [];
|
22 |
|
23 |
|
24 |
|
25 | for (var i = 1; i <= limit; i++) {
|
26 | fibonacciNumbers.push(fibonacci(i));
|
27 | bar.update(i);
|
28 | }
|
29 |
|
30 | bar.stop();
|
31 |
|
32 |
|
33 | console.log('\nFibonacci (1-', fibonacciNumbers.length,'): ', fibonacciNumbers.join(', '));
|