8000 Merge branch 'jest' · davidnth/javascript-exercises@f76e9e1 · GitHub
[go: up one dir, main page]

Skip to content

Commit f76e9e1

Browse files
committed
Merge branch 'jest'
2 parents f238dee + 8430e59 commit f76e9e1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+6165
-216
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
generator-exercise/

.eslintrc.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"plugins": [
3+
"import"
4+
],
5+
"parserOptions": {
6+
"ecmaVersion": 12,
7+
"sourceType": "module"
8+
},
9+
"rules": {
10+
"eol-last": ["error", "always"]
11+
}
12+
}

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
.vscode
1+
.vscode
2+
node_modules/
3+
.DS_Store

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Before you start you should have a few things installed on your machine:
1414

1515
Each exercise includes 3 files: a markdown file with a description of the task, an empty (or mostly empty) JavaScript file, and a set of tests. To complete an exercise, you'll need to go to the exercise directory with `cd exerciseName` in the terminal and run `jasmine exerciseName.spec.js`. This should run the test file and show you the output. When you first run a test, it will fail. This is by design! You must open the exercise file and write the code needed to get the test to pass. Some of the exercises have test conditions defined in their spec file that are defined as 'xit' compared to 'it'. This is purposeful. After you pass your first 'it', you will change the next 'xit' to an 'it' and test your code again. You'll do this until all conditions are satisfied.
1616

17+
**Note**: Due to the way Jest handles failed tests, it may return an exit code of 1 if any tests fail. NPM will interpret this as an error and you may see some `npm ERR!` messages after Jest runs. You can ignore these, or run your test with `npm test exerciseName.spec.js --silent` to supress the errors.
18+
1719
The first exercise, `helloWorld`, will walk you through the process in-depth.
1820

1921
## Solutions

caesar/README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Exercise XX - caesar cipher
1+
# Exercise 13 - Caesar cipher
22

3-
Implement the legendary caesar cipher:
3+
Implement the legendary Caesar cipher:
44

55
> In cryptography, a Caesar cipher, also known as Caesar's cipher, the shift cipher, Caesar's code or Caesar shift, is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. For example, with a left shift of 3, D would be replaced by A, E would become B, and so on. The method is named after Julius Caesar, who used it in his private correspondence.
66
@@ -31,5 +31,3 @@ negative numbers should work as well:
3131
```javascript
3232
caesar('Mjqqt, Btwqi!', -5) // returns 'Hello, World!'
3333
```
34-
35-

caesar/caesar.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const caesar = function() {
22

3-
}
3+
};
44

5-
module.exports = caesar
5+
module.exports = caesar;

calculator/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
# Exercise 08 - Calculator
2+
13
The goal for this exercise is to create a calculator that does the following:
24

35
add, subtract, get the sum, multiply, get the power, and find the factorial
46

5-
In order to do this please fill out each function with your solution. Make sure to return the value so you can test it in Jasmine! To see the expected value
6-
take a look at the spec file that houses the Jasmine test cases.
7+
In order to do this please fill out each function with your solution. Make sure to return the value so you can test it in Jest! To see the expected value
8+
take a look at the spec file that houses the Jest test cases.

calculator/calculator.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
function add () {
1+
const add = function() {
22

3-
}
3+
};
44

5-
function subtract () {
5+
const subtract = function() {
66

7-
}
7+
};
88

9-
function sum () {
9+
const sum = function() {
1010

11-
}
11+
};
1212

13-
function multiply () {
14-
15-
}
13+
const multiply = function() {
1614

17-
function power() {
15+
};;
16+
17+
const power = function() {
1818

19-
}
19+
};
2020

21-
function factorial() {
21+
const factorial = function() {
2222

23-
}
23+
};
2424

2525
module.exports = {
2626
add,
2727
subtract,
2828
sum,
2929
multiply,
3030
power,
31-
factorial,
31+
factorial
3232
};

calculator/calculator.spec.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,56 @@
1-
const calculator = require ('./calculator.js');
1+
const calculator = require('./calculator');
22

33
describe('add', function() {
44
it('adds 0 and 0', function() {
55
expect(calculator.add(0,0)).toEqual(0);
66
});
77

8-
xit('adds 2 and 2', function() {
9-
expect(calculator.add(2,2)).toEqual(4);
8+
test.skip('adds 2 and 2', () => {
9+
expect(calculator.add(2,2)).toBe(4);
1010
});
1111

12-
xit('adds positive numbers', function() {
13-
expect(calculator.add(2,6)).toEqual(8);
12+
test.skip('adds positive numbers', () => {
13+
expect(calculator.add(2,6)).toBe(8);
1414
});
1515
});
1616

17-
describe('subtract', function() {
18-
xit('subtracts numbers', function() {
19-
expect(calculator.subtract(10,4)).toEqual(6);
17+
describe('subtract', () => {
18+
test.skip('subtracts numbers', () => {
19+
expect(calculator.subtract(10,4)).toBe(6);
2020
});
2121
});
2222

23-
describe('sum', function() {
24-
xit('computes the sum of an empty array', function() {
25-
expect(calculator.sum([])).toEqual(0);
23+
describe('sum', () => {
24+
test.skip('computes the sum of an empty array', () => {
25+
expect(calculator.sum([])).toBe(0);
26 10000 26
});
2727

28-
xit('computes the sum of an array of one number', function() {
29-
expect(calculator.sum([7])).toEqual(7);
28+
test.skip('computes the sum of an array of one number', () => {
29+
expect(calculator.sum([7])).toBe(7);
3030
});
3131

32-
xit('computes the sum of an array of two numbers', function() {
33-
expect(calculator.sum([7,11])).toEqual(18);
32+
test.skip('computes the sum of an array of two numbers', () => {
33+
expect(calculator.sum([7,11])).toBe(18);
3434
});
3535

36-
xit('computes the sum of an array of many numbers', function() {
37-
expect(calculator.sum([1,3,5,7,9])).toEqual(25);
36+
test.skip('computes the sum of an array of many numbers', () => {
37+
expect(calculator.sum([1,3,5,7,9])).toBe(25);
3838
});
3939
});
4040

41-
describe('multiply', function() {
42-
xit('multiplies two numbers', function() {
43-
expect(calculator.multiply([2,4])).toEqual(8);
41+
describe('multiply', () => {
42+
test.skip('multiplies two numbers', () => {
43+
expect(calculator.multiply([2,4])).toBe(8);
4444
});
4545

46-
xit('multiplies several numbers', function() {
47-
expect(calculator.multiply([2,4,6,8,10,12,14])).toEqual(645120);
46+
test.skip('multiplies several numbers', () => {
47+
expect(calculator.multiply([2,4,6,8,10,12,14])).toBe(645120);
4848
});
4949
});
5050

51-
describe('power', function() {
52-
xit('raises one number to the power of another number', function() {
53-
expect(calculator.power(4,3)).toEqual(64); // 4 to third power is 64
51+
describe('power', () => {
52+
test.skip('raises one number to the power of another number', () => {
53+
expect(calculator.power(4,3)).toBe(64); // 4 to third power is 64
5454
});
5555
});
5656

fibonacci/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Exercise XX - fibonacci
1+
# Exercise 10 - Fibonacci
22

3-
Create a function that returns a specific member of the fibonacci sequence:
3+
Create a function that returns a specific member of the Fibonacci sequence:
44

5-
> a series of numbers in which each number ( Fibonacci number ) is the sum of the two preceding numbers. The simplest is the series 1, 1, 2, 3, 5, 8, etc.
5+
> A series of numbers in which each number ( Fibonacci number ) is the sum of the two preceding numbers. The simplest is the series 1, 1, 2, 3, 5, 8, etc.
66
77
```javascript
88
fibonacci(4) // returns the 4th member of the series: 3 (1, 1, 2, 3)

0 commit comments

Comments
 (0)
0