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.
1 parent 86a63e3 commit 0692f23Copy full SHA for 0692f23
src/code-challenges/code-challenges-002-010.js
@@ -193,3 +193,18 @@ exports.iterative = function (array) {
193
module.exports = function (a, b) {
194
return a.length === b.length && (a + a).indexOf(b) > -1;
195
};
196
+
197
+/**
198
+ * Q009: Return the N-th value of the Fibonacci sequence. Solve in O(n)
199
+ */
200
201
+// The easiest solution that comes to mind here is iteration.
202
203
+function fibonacciNumbers(n) {
204
+ let arr = [0, 1];
205
206
+ for (let i = 2; i < n + 1; i++) {
207
+ arr.push(arr[i - 2] + arr[i - 1]);
208
+ }
209
+ return arr[n];
210
+}
0 commit comments