Skip to content

Commit e55ab27

Browse files
author
sunjieming
committed
Update
1 parent 2f10384 commit e55ab27

File tree

10 files changed

+97
-20
lines changed

10 files changed

+97
-20
lines changed

.eslintrc.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
"linebreak-style": 0,
1212
"consistent-return": 0,
1313
"no-useless-return": 0,
14-
"no-return-assign": 0
14+
"no-return-assign": 0,
15+
"comma-dangle": 0,
16+
"arrow-body-style": 0,
17+
"max-len": 0,
18+
"no-unused-vars": 0,
19+
"no-useless-constructor": 0
1520
}
1621
}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
## Instructions
44

55
Fork and clone this repo.
6-
6+
77
* Run the command `npm i` to install needed node packages.
88
* Run the command `npm test` to run the tests.
99
* Work through the files and make the tests pass.
10-
* Suggested order: `es6.js`, `arrays.js`, `objects.js`, `this.js`, `closure.js`, and then `recursion.js`.
10+
* Suggested order: `es6.js`, `arrays.js`, `objects.js`, `this.js`, `class.js`, `closure.js`, and then `recursion.js`.
1111
* Submit a pull request when you are finished and we will review your code.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "LambdaSchool's JavaScript Mini-Bootcamp Homework 1",
55
"main": "index.js",
66
"scripts": {
7-
"test": "eslint tests/*.js && eslint src/*.js && jest",
7+
"test": "eslint tests/*.js && eslint src/*.js && jest --verbose",
88
"test:watch": "npm test -- --watch"
99
},
1010
"repository": {

src/arrays.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Complete the following functions.
22
// These functions only need to work with arrays.
33

4-
/* eslint-disable no-unused-vars, max-len */
54

65
const each = (elements, cb) => {
76
// Iterates over a list of elements, yielding each in turn to the `cb` function.
@@ -44,5 +43,5 @@ module.exports = {
4443
reduce,
4544
find,
4645
filter,
47-
flatten,
46+
flatten
4847
};

src/class.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Create a class called User.
2+
// The constructor of the class should have a parameter called `options`.
3+
// `options` will be an object that will have the properties `email` and `password`.
4+
// Set the `email` and `password` properties on the class.
5+
// Add a method called `comparePasswords`. `comparePasswords` should have a parameter
6+
// for a potential password that will be compared to the `password` property.
7+
// Return true if the potential password matches the `password` property. Otherwise return false.
8+
9+
10+
/* eslint-disable no-undef */ // Remove this comment once you write your classes.
11+
12+
13+
// Create a class called `Animal` and a class called `Cat`.
14+
// `Cat` should extend the `Animal` class.
15+
// Animal and Cat should both have a parameter called `options` in their constructors.
16+
// Animal should have the property `age` that's set in the constructor and the method
17+
// `growOlder` that returns the age.
18+
// Cat should have the property `name` that is set in the constructor and the method
19+
// `meow` that should return the string `<name> meowed!` where `<name>` is the `name`
20+
// property set on the Cat instance.
21+
22+
23+
module.exports = {
24+
User,
25+
Cat
26+
};

src/closure.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// Complete the following functions.
22

3-
/* eslint-disable no-unused-vars */
4-
53
const counter = () => {
64
// Return a function that when invoked increments and returns a counter variable.
75
// Example: const newCounter = counter();
@@ -35,5 +33,5 @@ module.exports = {
3533
counter,
3634
counterFactory,
3735
cacheFunction,
38-
limitFunctionCallCount,
36+
limitFunctionCallCount
3937
};

src/objects.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Complete the following underscore functions.
22
// Reference http://underscorejs.org/ for examples.
33

4-
/* eslint-disable no-unused-vars */
5-
64
const keys = (obj) => {
75
// Retrieve all the names of the object's properties.
86
// Return the keys as strings in an array.
@@ -45,5 +43,5 @@ module.exports = {
4543
mapObject,
4644
pairs,
4745
invert,
48-
defaults,
46+
defaults
4947
};

src/recursion.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// Complete the following functions.
22

3-
/* eslint-disable no-unused-vars */
4-
53
const nFibonacci = (n) => {
64
// fibonacci sequence: 1 2 3 5 8 13 ...
75
// return the nth number in the sequence
@@ -22,5 +20,5 @@ const checkMatchingLeaves = (obj) => {
2220
module.exports = {
2321
nFibonacci,
2422
nFactorial,
25-
checkMatchingLeaves,
23+
checkMatchingLeaves
2624
};

src/this.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// There are no tests for this file.
33
// To verify your code works you can run this file using `node this.js` while in the `/src` folder
44

5-
/* eslint-disable no-useless-constructor, no-unused-vars */
6-
75
class User {
86
constructor(options) {
97
// set a username and password property on the user object that is created
@@ -13,8 +11,6 @@ class User {
1311
// return `true` if they match, otherwise return `false`
1412
}
1513

16-
/* eslint-enable no-useless-constructor */
17-
1814
const me = new User({ username: 'LambdaSchool', password: 'correcthorsebatterystaple' });
1915
const result = me.checkPassword('correcthorsebatterystaple'); // should return `true`
2016

@@ -25,7 +21,6 @@ const checkPassword = function comparePasswords(passwordToCompare) {
2521
// note that we use the `function` keyword and not `=>`
2622
};
2723

28-
/* eslint-enable no-unused-vars */
2924
// invoke `checkPassword` on `me` by explicitly setting the `this` context
3025
// use .call, .apply, and .bind
3126

tests/class.test.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
const {
2+
User,
3+
Cat
4+
} = require('../src/class');
5+
6+
/* eslint-disable no-undef */
7+
describe('classes', () => {
8+
describe('User', () => {
9+
it('should be a valid JS class', () => {
10+
expect(typeof User).toBe('function');
11+
expect(Array.isArray(new User({}))).toBe(false);
12+
expect(typeof new User({})).toBe('object');
13+
});
14+
15+
it('should set an email and password property from the provided options object', () => {
16+
const user = new User({
17+
18+
password: 'correcthorsebatterystaple'
19+
});
20+
expect(user.email).toBe('[email protected]');
21+
expect(user.password).toBe('correcthorsebatterystaple');
22+
expect(Object.keys(user).length).toBe(2);
23+
});
24+
25+
it('should have a working comparePasswords method that returns a boolean value', () => {
26+
const user = new User({
27+
28+
password: 'correcthorsebatterystaple'
29+
});
30+
31+
expect(typeof user.comparePasswords).toBe('function');
32+
expect(user.comparePasswords('sup')).toBe(false);
33+
expect(user.comparePasswords('correcthorsebatterystaple')).toBe(true);
34+
expect(user.comparePasswords()).toBe(false);
35+
});
36+
});
37+
describe('Cat', () => {
38+
it('should have the properties name and age and the methods growOlder and meow', () => {
39+
const snowball = new Cat({
40+
name: 'Snowball II',
41+
age: 5
42+
});
43+
expect(snowball).toHaveProperty('name');
44+
expect(snowball).toHaveProperty('age');
45+
expect(typeof snowball.growOlder).toBe('function');
46+
expect(typeof snowball.meow).toBe('function');
47+
});
48+
it('should inherit properties and methods from Animal', () => {
49+
const snowball = new Cat({
50+
name: 'Snowball II',
51+
age: 5
52+
});
53+
expect(Object.prototype.hasOwnProperty.call(Object.getPrototypeOf(snowball), 'growOlder')).toBe(false);
54+
expect(snowball.age).toBe(5);
55+
expect(snowball.growOlder()).toBe(6);
56+
});
57+
});
58+
});

0 commit comments

Comments
 (0)