UNPKG

991 BJavaScriptView Raw
1var _progress = require('./main');
2var limit = 43;
3
4// long running, recursive function (blocking operation)
5// well it's no optimized and not for productive use but it's an easy way to implement a long-running & blocking operation without third-party modules
6function fibonacci(n) {
7 if (n < 2) {
8 return 1;
9 }else {
10 return fibonacci(n - 2) + fibonacci(n - 1);
11 }
12}
13
14// create new progress bar using default values
15var bar = new _progress.Bar({
16 format: 'Fibonacci Calculation Progress [{bar}] {percentage}% | ETA: {eta}s | Current: F({value})',
17 hideCursor: true
18});
19bar.start(limit, 1);
20
21var fibonacciNumbers = [];
22
23// calculate the Nth fibonacci
24// this loop is executed synchronous - no timer/interval callbacks will be executed
25for (var i = 1; i <= limit; i++) {
26 fibonacciNumbers.push(fibonacci(i));
27 bar.update(i);
28}
29
30bar.stop();
31
32// display the numbers:
33console.log('\nFibonacci (1-', fibonacciNumbers.length,'): ', fibonacciNumbers.join(', '));