Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"plugins": [
"import"
],
"consistent-return": 0,
"rules": {
"no-param-reassign": 0,
"max-len": 0,
Expand Down
28 changes: 27 additions & 1 deletion src/class.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Part 1
// Create a class called User using the ES6 class keyword.

// The constructor of the class should have a parameter called `options`.
// `options` will be an object that will have the properties `email` and `password`.
// Set the `email` and `password` properties on the class.
Expand All @@ -8,7 +9,15 @@
// Return true if the potential password matches the `password` property. Otherwise return false.

// code here

class User {
constructor(options) {
this.email = options.email;
this.password = options.password;
}
comparePasswords(password) {
return this.password === password;
}
};
// Part 2
// Create a class called `Animal` and a class called `Cat` using ES6 classes.
// `Cat` should extend the `Animal` class.
Expand All @@ -20,7 +29,24 @@
// property set on the Cat instance.

// code here
class Animal {
constructor(options) {
this.age = options.age;
}
growOlder() {
return this.age++;
}
};

class Cat extends Animal{
constructor(options) {
super(CatOptions)
this.name = options.name;
}
meow() {
return `${this.name} meowed!`;
}
};
/* eslint-disable no-undef */

module.exports = {
Expand Down
13 changes: 12 additions & 1 deletion src/recursion.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,28 @@
const nFibonacci = (n) => {
// fibonacci sequence: 1 1 2 3 5 8 13 ...
// return the nth number in the sequence
if(n <= 2) {
return 1;
} else {
return (n - 1) + (n - 2);
}
};
console.log(nFibonacci(8));

const nFactorial = (n) => {
// factorial example: !5 = 5 * 4 * 3 * 2 * 1
// return the factorial of `n`
if (n === 0) {
return 1;
}
return n * nFactorial(n - 1);
};

console.log(nFactorial(5));
/* Extra Credit */
const checkMatchingLeaves = (obj) => {
// return true if every property on `obj` is the same
// otherwise return false

};

/* eslint-enable no-unused-vars */
Expand Down
24 changes: 16 additions & 8 deletions src/this.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,41 @@
class User {
constructor(options) {
// set a username and password property on the user object that is created
this.username = options.username;
this.password = options.password;
// create a method on the User class called `checkPassword`
// this method should take in a string and compare it to the object's password property
// return `true` if they match, otherwise return `false`
}
// create a method on the User class called `checkPassword`
// this method should take in a string and compare it to the object's password property
// return `true` if they match, otherwise return `false`
}
checkPassword(passwordCheck){
return passwordCheck === this.password;
}
};

const me = new User({
username: 'LambdaSchool',
password: 'correcthorsebatterystaple',
});

const result = me.checkPassword('correcthorsebatterystaple'); // should return `true`

console.log(result)
/* part 2 */

const checkPassword = function comparePasswords(passwordToCompare) {
// recreate the `checkPassword` method that you made on the `User` class
// use `this` to access the object's `password` property.
// do not modify this function's parameters
// note that we use the `function` keyword and not `=>`
return this.password === passwordToCompare;
};

const correctPassword = 'correcthorsebatterystaple'
// invoke `checkPassword` on `me` by explicitly setting the `this` context
// use .call, .apply, and .bind

// .call

console.log(checkPassword.call(me, correctPassword));
// .apply

console.log(checkPassword.apply(me, [correctPassword]));
// .bind
const bindFunction = checkPassword.bind(me);
console.log(bindFunction(correctPassword));
Loading