Skip to content

Commit 63adbb8

Browse files
committed
completed recursion and this projects
1 parent 93e5e64 commit 63adbb8

File tree

4 files changed

+168
-19
lines changed

4 files changed

+168
-19
lines changed

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: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,26 @@
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
};
711

812
const nFactorial = (n) => {
913
// factorial example: !5 = 5 * 4 * 3 * 2 * 1
1014
// return the factorial of `n`
15+
const result = n - 1;
16+
if (n === 0) {
17+
return 1;
18+
}
19+
return n * nFactorial(result);
1120
};
1221

1322
/* Extra Credit */
1423
const checkMatchingLeaves = (obj) => {
1524
// return true if every property on `obj` is the same
16-
// otherwise return false
25+
// otherwise return false
1726
};
1827

1928
/* eslint-enable no-unused-vars */

src/this.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@
77
class User {
88
constructor(options) {
99
// set a username and password property on the user object that is created
10+
this.username = options.username;
11+
this.password = options.password;
1012
}
1113
// create a method on the User class called `checkPassword`
1214
// this method should take in a string and compare it to the object's password property
1315
// return `true` if they match, otherwise return `false`
16+
checkPassword(str) {
17+
return str === this.password;
18+
}
1419
}
1520

1621
const me = new User({
@@ -27,13 +32,17 @@ const checkPassword = function comparePasswords(passwordToCompare) {
2732
// use `this` to access the object's `password` property.
2833
// do not modify this function's parameters
2934
// note that we use the `function` keyword and not `=>`
35+
return passwordToCompare === this.password;
3036
};
3137

3238
// invoke `checkPassword` on `me` by explicitly setting the `this` context
3339
// use .call, .apply, and .bind
3440

3541
// .call
42+
checkPassword.call(me, 'correcthorsebatterystaple');
3643

3744
// .apply
45+
checkPassword.apply(me, ['correcthorsebatterystaple']);
3846

3947
// .bind
48+
checkPassword.bind(me, 'correcthorsebatterystaple');

0 commit comments

Comments
 (0)