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 94a316a + df075ad commit d60b8b8Copy full SHA for d60b8b8
src/others/fibonacci.js
@@ -0,0 +1,37 @@
1
+/**
2
+ * Nth number of fibonacci's sequence
3
+ *
4
+ * Returns the nth number of fibonacci's sequence.
5
6
+ * @public
7
8
+ * @example
9
+ * var fibonacci = require('path-to-algorithms/src/others/fibonacci').fibonacci;
10
+ * var nth = fibonacci(20);
11
12
+ * console.log(nth); // 6765
13
14
+ * @param {Number} n The nth position in fibonacci's sequence
15
16
+ * @module others/fibonacci
17
+*/
18
+(function (exports) {
19
+ 'use strict';
20
+
21
+ function fibonacci (n) {
22
+ var n1 = 0;
23
+ var n2 = 1;
24
+ var aux;
25
26
+ while (n > 0) {
27
+ aux = n1;
28
+ n1 = n2;
29
+ n2 += aux;
30
+ n = n - 1;
31
+ }
32
33
+ return n1;
34
35
36
+ exports.fibonacci = fibonacci;
37
+})(typeof window === 'undefined' ? module.exports : window);
0 commit comments