8000 Merge branch 'origin/master' into 'jest' · unconnect/javascript-exercises@8430e59 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8430e59

Browse files
committed
Merge branch 'origin/master' into 'jest'
2 parents 14f9b66 + f238dee commit 8430e59

File tree

16 files changed

+129
-122
lines changed

16 files changed

+129
-122
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ There will eventually be a suggested order of completion, but at this time since
99
## How To Use These Exercises
1010
Before you start you should have a few things installed on your machine:
1111
1. NPM. To check if you have NPM installed, type `npm --version` in your terminal. If you get back `Command 'npm' not found, but can be installed with:`, do NOT follow the instructions in the terminal to install with `apt-get`. (This causes permission issues.) Instead, install Node with NVM by following the instructions [here](https://github.com/TheOdinProject/curriculum/blob/master/foundations/installations/installing_node.md).
12-
2. Jest. Jest is a testing framework for JavaScript. To install it, type `npm install --save-dev jest`. We use `--save-dev` here to specify this module is for development purposes only.
13-
3. A copy of this repository. Copies of repositories on your machine are called clones. If you need help cloning, you can learn how [here](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository).
12+
2. Jasmine. Jasmine is a testing framework for JavaScript. Type `jasmine -v` to check for it. If you need to install it, type `npm install -g jasmine` to do so.
13+
3. A copy of this repository. Copies of repositories on your machine are called clones. If you need help cloning, you can learn how [here](https://docs.github.com/en/free-pro-team@latest/github/creating-cloning-and-archiving-repositories/duplicating-a-repository)
1414

15-
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 `npm test 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 'test.skip' compared to 'test'. This is purposeful. After you pass your first 'test', you will change the next 'test.skip' to an 'test' and test your code again. You'll do this until all conditions are satisfied.
15+
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

1717
**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.
1818

caesar/caesar.spec.js

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
const caesar = require('./caesar')
22

3-
test('works with single letters', () => {
4-
expect(caesar('A', 1)).toBe('B');
5-
});
6-
test.skip('works with words', () => {
7-
expect(caesar('Aaa', 1)).toBe('Bbb');
8-
});
9-
test.skip('works with phrases', () => {
10-
expect(caesar('Hello, World!', 5)).toBe('Mjqqt, Btwqi!');
11-
});
12-
test.skip('works with negative shift', () => {
13-
expect(caesar('Mjqqt, Btwqi!', -5)).toBe('Hello, World!');
14-
});
15-
test.skip('wraps', () => {
16-
expect(caesar('Z', 1)).toBe('A');
17-
});
18-
test.skip('works with large shift factors', () => {
19-
expect(caesar('Hello, World!', 75)).toBe('Ebiil, Tloia!');
20-
});
21-
test.skip('works with large negative shift factors', () => {
22-
expect(caesar('Hello, World!', -29)).toBe('Ebiil, Tloia!');
3+
describe('caesar', function() {
4+
it('works with single letters', function() {
5+
expect(caesar('A', 1)).toEqual('B');
6+
});
7+
xit('works with words', function() {
8+
expect(caesar('Aaa', 1)).toEqual('Bbb');
9+
});
10+
xit('works with phrases', function() {
11+
expect(caesar('Hello, World!', 5)).toEqual('Mjqqt, Btwqi!');
12+
});
13+
xit('works with negative shift', function() {
14+
expect(caesar('Mjqqt, Btwqi!', -5)).toEqual('Hello, World!');
15+
});
16+
xit('wraps', function() {
17+
expect(caesar('Z', 1)).toEqual('A');
18+
});
19+
xit('works with large shift factors', function() {
20+
expect(caesar('Hello, World!', 75)).toEqual('Ebiil, Tloia!');
21+
});
22+
xit('works with large negative shift factors', function() {
23+
expect(caesar('Hello, World!', -29)).toEqual('Ebiil, Tloia!');
24+
});
2325
});

calculator/calculator.spec.js

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

3-
describe('add', () => {
4-
test('adds 0 and 0', () => {
5-
expect(calculator.add(0,0)).toBe(0);
3+
describe('add', function() {
4+
it('adds 0 and 0', function() {
5+
expect(calculator.add(0,0)).toEqual(0);
66
});
77

88
test.skip('adds 2 and 2', () => {
@@ -54,24 +54,24 @@ describe('power', () => {
5454
});
5555
});
5656

57-
describe('factorial', () => {
58-
test.skip('computes the factorial of 0', () => {
59-
expect(calculator.factorial(0)).toBe(1); // 0! = 1
57+
describe('factorial', function() {
58+
xit('computes the factorial of 0', function() {
59+
expect(calculator.factorial(0)).toEqual(1); // 0! = 1
6060
});
6161

62-
test.skip('computes the factorial of 1', () => {
63-
expect(calculator.factorial(1)).toBe(1);
62+
xit('computes the factorial of 1', function() {
63+
expect(calculator.factorial(1)).toEqual(1);
6464
});
6565

66-
test.skip('computes the factorial of 2', () => {
67-
expect(calculator.factorial(2)).toBe(2);
66+
xit('computes the factorial of 2', function() {
67+
expect(calculator.factorial(2)).toEqual(2);
6868
});
6969

70-
test.skip('computes the factorial of 5', () => {
71-
expect(calculator.factorial(5)).toBe(120);
70+
xit('computes the factorial of 5', function() {
71+
expect(calculator.factorial(5)).toEqual(120);
7272
});
7373

74-
test.skip('computes the factorial of 10', () => {
75-
expect(calculator.factorial(10)).toBe(3628800);
74< F438 code class="diff-text syntax-highlighted-line addition">+
xit('computes the factorial of 10', function() {
75+
expect(calculator.factorial(10)).toEqual(3628800);
7676
});
7777
});

fibonacci/fibonacci.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const fibonacci = function() {
1+
const fibonacci = function () {};
22

33
};
4-
5-
module.exports = fibonacci;

fibonacci/fibonacci.spec.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
const fibonacci = require('./fibonacci')
22

3-
describe('fibonacci', () => {
4-
test('4th fibonacci number is 3', () => {
5-
expect(fibonacci(4)).toBe(3);
3+
describe('fibonacci', function() {
4+
it('works', function() {
5+
expect(fibonacci(4)).toEqual(3);
66
});
7-
test.skip('6th fibonacci number is 8', () => {
8-
expect(fibonacci(6)).toBe(8);
7+
xit('works', function() {
8+
expect(fibonacci(6)).toEqual(8);
99
});
10-
test.skip('10th fibonacci number is 55', () => {
11-
expect(fibonacci(10)).toBe(55);
10+
xit('works', function() {
11+
expect(fibonacci(10)).toEqual(55);
1212
});
13-
test.skip('15th fibonacci number is 610', () => {
14-
expect(fibonacci(15)).toBe(610);
13+
xit('works', function() {
14+
expect(fibonacci(15)).toEqual(610);
1515
});
16-
test.skip('25th fibonacci number is 75025', () => {
17-
expect(fibonacci(25)).toBe(75025);
16+
xit('works', function() {
17+
expect(fibonacci(25)).toEqual(75025);
1818
});
19-
test.skip('doesn\'t accept negatives', () => {
20-
expect(fibonacci(-25)).toBe("OOPS");
19+
xit('doesn\'t accept negatives', function() {
20+
expect(fibonacci(-25)).toEqual("OOPS");
2121
});
22-
test.skip('DOES accept strings', () => {
23-
expect(fibonacci("1")).toBe(1);
22+
xit('DOES accept strings', function() {
23+
expect(fibonacci("1")).toEqual(1);
2424
});
25-
test.skip('DOES accept strings', () => {
26-
expect(fibonacci("2")).toBe(1);
25+
xit('DOES accept strings', function() {
26+
expect(fibonacci("2")).toEqual(1);
2727
});
28-
test.skip('DOES accept strings', () => {
29-
expect(fibonacci("8")).toBe(21);
28+
xit('DOES accept strings', function() {
29+
expect(fibonacci("8")).toEqual(21);
3030
});
3131
});

findTheOldest/findTheOldest.spec.js

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,62 @@
1-
const findTheOldest = require('./findTheOldest')
1+
let findTheOldest = require('./findTheOldest')
22

3-
describe('findTheOldest', () => {
4-
test('finds the oldest person!', () => {
3+
describe('findTheOldest', function() {
4+
it('finds the oldest person!', function() {
55
const people = [
66
{
7-
name: 'Carly',
7+
name: "Carly",
88
yearOfBirth: 1942,
99
yearOfDeath: 1970,
1010
},
1111
{
12-
name: 'Ray',
12+
name: "Ray",
1313
yearOfBirth: 1962,
14-
yearOfDeath: 2011
14+
yearOfDeath: 2011,
1515
},
1616
{
17-
name: 'Jane',
17+
name: "Jane",
1818
yearOfBirth: 1912,
19-
yearOfDeath: 1941
19+
yearOfDeath: 1941,
2020
},
2121
]
22-
expect(findTheOldest(people).name).toBe('Ray');
22+
expect(findTheOldest(people).name).toEqual('Ray');
2323
});
24-
test.skip('finds the oldest person if someone is still living', () => {
24+
xit('finds the oldest person if someone is still living', function() {
2525
const people = [
2626
{
27-
name: 'Carly',
27+
name: "Carly",
2828
yearOfBirth: 2018,
2929
},
3030
{
31-
name: 'Ray',
31+
name: "Ray",
3232
yearOfBirth: 1962,
33-
yearOfDeath: 2011
33+
yearOfDeath: 2011,
3434
},
3535
{
36-
name: 'Jane',
36+
name: "Jane",
3737
yearOfBirth: 1912,
38-
yearOfDeath: 1941
38+
yearOfDeath: 1941,
3939
},
4040
]
41-
expect(findTheOldest(people).name).toBe('Ray');
41+
expect(findTheOldest(people).name).toEqual('Ray');
4242
});
43-
test.skip('finds the oldest person if the OLDEST is still living', () => {
43+
xit('finds the oldest person if the OLDEST is still living', function() {
4444
const people = [
4545
{
46-
name: 'Carly',
46+
name: "Carly",
4747
yearOfBirth: 1066,
4848
},
4949
{
50-
name: 'Ray',
50+
name: "Ray",
5151
yearOfBirth: 1962,
52-
yearOfDeath: 2011
52+
yearOfDeath: 2011,
5353
},
5454
{
55-
name: 'Jane',
55+
name: "Jane",
5656
yearOfBirth: 1912,
57-
yearOfDeath: 1941
57+
yearOfDeath: 1941,
5858
},
5959
]
60-
expect(findTheOldest(people).name).toBe('Carly');
60+
expect(findTheOldest(people).name).toEqual('Carly');
6161
});
62-
6362
});

getTheTitles/getTheTitles.spec.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const getTheTitles = require('./getTheTitles')
1+
let getTheTitles = require('./getTheTitles')
22

3-
describe('getTheTitles', () => {
3+
describe('getTheTitles', function() {
44
const books = [
55
{
66
title: 'Book',
@@ -15,5 +15,4 @@ describe('getTheTitles', () => {
1515
test('gets titles', () => {
1616
expect(getTheTitles(books)).toEqual(['Book','Book2']);
1717
});
18-
1918
});

helloWorld/helloWorld.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ const helloWorld = function() {
22
return ''
33
}
44

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

helloWorld/helloWorld.spec.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const helloWorld = require('./helloWorld');
22

3-
test('says "Hello, World!"', function() {
4-
expect(helloWorld()).toBe("Hello, World!");
3+
describe('Hello World', function() {
4+
it('says hello world', function() {
5+
expect(helloWorld()).toEqual('Hello, World!');
6+
});
57
});

leapYears/leapYears.spec.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
const leapYears = require('./leapYears')
22

3-
describe('leapYears', () => {
4-
test('works with non century years', () => {
5-
expect(leapYears(1996)).toBe(true);
3+
describe('leapYears', function() {
4+
it('works with non century years', function() {
5+
expect(leapYears(1996)).toEqual(true);
66
});
7-
test.skip('works with non century years', () => {
8-
expect(leapYears(1997)).toBe(false);
7+
xit('works with non century years', function() {
8+
expect(leapYears(1997)).toEqual(false);
99
});
10-
test.skip('works with ridiculously futuristic non century years', () => {
11-
expect(leapYears(34992)).toBe(true);
10+
xit('works with ridiculously futuristic non century years', function() {
11+
expect(leapYears(34992)).toEqual(true);
1212
});
13-
test.skip('works with century years', () => {
14-
expect(leapYears(1900)).toBe(false);
13+
xit('works with century years', function() {
14+
expect(leapYears(1900)).toEqual(false);
1515
});
16-
test.skip('works with century years', () => {
17-
expect(leapYears(1600)).toBe(true);
16+
xit('works with century years', function() {
17+
expect(leapYears(1600)).toEqual(true);
1818
});
19-
test.skip('works with century years', () => {
20-
expect(leapYears(700)).toBe(false);
19+
xit('works with century years', function() {
20+
expect(leapYears(700)).toEqual(false);
2121
});
2222
});

palindromes/palindromes.js

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

33
};
44

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

palindromes/palindromes.spec.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
const palindromes = require('./palindromes')
22

3-
describe('palindromes', () => {
4-
test('works with single words', () => {
5-
expect(palindromes('racecar')).toBe(true);
3+
describe('palindromes', function() {
4+
it('works with single words', function() {
5+
expect(palindromes('racecar')).toEqual(true);
66
});
7-
test.skip('works with punctuation ', () => {
8-
expect(palindromes('racecar!')).toBe(true);
7+
xit('works with punctuation ', function() {
8+
expect(palindromes('racecar!')).toEqual(true);
99
});
10-
test.skip('works with upper-case letters ', () => {
11-
expect(palindromes('Racecar!')).toBe(true);
10+
xit('works with upper-case letters ', function() {
11+
expect(palindromes('Racecar!')).toEqual(true);
1212
});
13-
test.skip('works with multiple words', () => {
14-
expect(palindromes('A car, a man, a maraca.')).toBe(true);
13+
xit('works with multiple words', function() {
14+
expect(palindromes('A car, a man, a maraca.')).toEqual(true);
1515
});
16-
test.skip('works with multiple words', () => {
17-
expect(palindromes('Animal loots foliated detail of stool lamina.')).toBe(true);
16+
xit('works with multiple words', function() {
17+
expect(palindromes('Animal loots foliated detail of stool lamina.')).toEqual(true);
1818
});
19-
test.skip('doesn\'t just always return true', () => {
20-
expect(palindromes('ZZZZ car, a man, a maraca.')).toBe(false);
19+
xit('doesn\'t just always return true', function() {
20+
expect(palindromes('ZZZZ car, a man, a maraca.')).toEqual(false);
2121
});
22-
2322
});

pigLatin/pigLatin.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ const pigLatin = require('./pigLatin')
77

88
// Pig Latin
99

10-
// Pig Latin is a made-up children's language that's intended to be confusing. test obeys a few simple rules (below) but when test's spoken quickly test's really difficult for non-children (and non-native speakers) to understand.
10+
// Pig Latin is a made-up children's language that's intended to be confusing. It obeys a few simple rules (below) but when it's spoken quickly it's really difficult for non-children (and non-native speakers) to understand.
1111

1212
// Rule 1: If a word begins with a vowel sound, add an "ay" sound to the end of the word.
1313

14-
// Rule 2: If a word begins with a consonant sound, move test to the end of the word, and then add an "ay" sound to the end of the word.
14+
// Rule 2: If a word begins with a consonant sound, move it to the end of the word, and then add an "ay" sound to the end of the word.
1515

1616
// (There are a few more rules for edge cases, and there are regional variants too, but that should be enough to understand the tests.)
1717

pig_latin/pigLatin.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function translate() {
2+
// body...
3+
}
4+
5+
6+
module.exports = {
7+
translate
8+
}
9+

repeatString/repeatString.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('repeatString', () => {
2424

2525
// DO NOT use Math.floor(Math.random() * 1000) in your code,
2626
// this test generates a random number, then passes it into your code with a function parameter.
27-
// If this doesn't make sense, you should go read about functions here: https://www.theodinproject.com/courses/web-development-101/lessons/fundamentals-part-3
27+
// If this doesn't make sense, you should go read about functions here: https://www.theodinproject.com/paths/foundations/courses/foundations/lessons/fundamentals-part-3
2828
const number = Math.floor(Math.random() * 1000)
2929
/*The .match(/((hey))/g).length is a regex that will count the number of heys
3030
in the result, which if your function works correctly will equal the number that

0 commit comments

Comments
 (0)
0