We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 157972d + 123e00d commit a3992aaCopy full SHA for a3992aa
10_fibonacci/solution/fibonacci-solution.js
@@ -4,14 +4,22 @@ const fibonacci = function(count) {
4
5
let firstPrev = 1;
6
let secondPrev = 0;
7
-
+
8
for (let i = 2; i <= count; i++) {
9
let current = firstPrev + secondPrev;
10
secondPrev = firstPrev;
11
firstPrev = current;
12
}
13
14
return firstPrev;
15
16
};
17
18
+// Another way to do it is by using an iterative approach with an array containing two values, 0 and 1.
19
+// const fib = [0, 1];
20
+// for (let i = 2; i <= count; i++) {
21
+// fib[i] = fib[i - 1] + fib[i - 2];
22
+// }
23
+// return fib[count];
24
25
module.exports = fibonacci;
0 commit comments