Files
Node.js-14-Cookbook/Chapter10/worker-app/fibonacci.js
T
2020-08-31 01:12:46 +01:00

15 lines
279 B
JavaScript

const n = 10;
// Fibonacci calculator
const fibonacci = (n) => {
let a = 0, b = 1, next = 1, i = 2;
for (i; i <= n; i++) {
next = a + b;
a = b;
b = next;
}
console.log(`The Fibonacci number at position ${n} is ${next}`);
};
fibonacci(n);
console.log("...");