Skip to content

Commit b796280

Browse files
committed
Finished nFactorial and nFibonacci
1 parent 93e5e64 commit b796280

3 files changed

Lines changed: 158 additions & 18 deletions

File tree

package-lock.json

Lines changed: 148 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"repository": {
1313
"type": "git",
1414
"url": "git+https://github.com/LambdaSchool/javascript-ii.git"
15-
},
15+
},
1616
"devDependencies": {
1717
"babel-jest": "^19.0.0",
1818
"eslint": "^3.17.1",

src/recursion.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,20 @@
33
const nFibonacci = (n) => {
44
// fibonacci sequence: 1 1 2 3 5 8 13 ...
55
// return the nth number in the sequence
6+
if (n <= 2) {
7+
return 1;
8+
}
9+
return nFibonacci(n - 1) + nFibonacci(n - 2);
610
};
11+
console.log(nFibonacci(5));
712

813
const nFactorial = (n) => {
914
// factorial example: !5 = 5 * 4 * 3 * 2 * 1
1015
// return the factorial of `n`
16+
if (n > 1) {
17+
return n * nFactorial(n - 1);
18+
}
19+
return n;
1120
};
1221

1322
/* Extra Credit */

0 commit comments

Comments
 (0)