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
38 changes: 38 additions & 0 deletions src/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@
// 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(pw) {
if (pw === this.password) return true;
return false;
}
}
// **********no semi colon in the end needed in class.*******




// Part 2
// Create a class called `Animal` and a class called `Cat` using ES6 classes.
Expand All @@ -21,6 +35,30 @@

// code here

class Animal {
constructor(options) {
this.age = options.age;
}
growOlder() {
return ++this.age; // growOlder(method) is outside of class constructor.
}
}

class Cat extends Animal {
constructor(options) {
super(options);
this.name = options.name;
}
meow() {
Console.log(this.name + 'meowed!'); // this is not working here.

//**return `${this.name 'meowed!'}`;
// return `${this.name} meowed!`;
// this is new in es6.
}
}


/* eslint-disable no-undef */

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

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

/* Extra Credit */
const checkMatchingLeaves = (obj) => {
// return true if every property on `obj` is the same
// otherwise return false
const checkMatchingLeaves = (obj) => {
let val;
let allMatch = true;
const checkLeaves = (object) => {
objects.keys(object).forEach((key) => {
if (val === undefined && typeof key !== 'object') {
val = object[key];
return undefined;
}
if (typeof object[key] === 'object')
return checkLeaves(object[key]);
if (object[key] !== val) {
allMatch = false;
return undefined;
});
};
checkLeaves(obj);
return allMatch;
};

/* eslint-enable no-unused-vars */
Expand Down
17 changes: 16 additions & 1 deletion src/this.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,33 @@

class User {
constructor(options) {
this.username = options.username;
this.password = options.password;
// set a username and password property on the user object that is created
}
checkPassword(passwordToCompare) {
return this.password === passwordToCompare;
}
// 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`
}



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

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

/* part 2 */

const checkPassword = function comparePasswords(passwordToCompare) {
return this.pasword === 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
Expand All @@ -33,7 +43,12 @@ const checkPassword = function comparePasswords(passwordToCompare) {
// use .call, .apply, and .bind

// .call
checkPassword.call(me, 'correcthorsebatterystaple');

// .apply
checkPassword.apply(me, 'correcthorsebatterystaple');

// .bind
const boundPasswordCheck = checkPassword.bind(me);
boundPasswordCheck('correcthorsebatterystaple');