Skip to content

Commit 55acb3e

Browse files
authored
Merge pull request #638 from KenjiroAI/nth-fibonacci-javascript
Add Nth Fibonacci for Javascript
2 parents 84c2eb5 + 3197eee commit 55acb3e

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

NthFibonacci/NthFibonacci.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
function fib(n) {
4+
let a = 0;
5+
let b = 1;
6+
7+
for (let i = 0; i < n; i++) {
8+
[a, b] = [b, a + b];
9+
}
10+
11+
return a;
12+
}
13+
14+
console.log(fib(10));

0 commit comments

Comments
 (0)