Revert "Merge branch 'jest'"

This reverts commit f76e9e108f.
This commit is contained in:
Marvin Gay 2021-05-12 21:47:42 -04:00
parent f76e9e108f
commit ad1c0c407f
45 changed files with 217 additions and 6166 deletions

View file

@ -1 +0,0 @@
generator-exercise/

View file

@ -1,12 +0,0 @@
{
"plugins": [
"import"
],
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"rules": {
"eol-last": ["error", "always"]
}
}

4
.gitignore vendored
View file

@ -1,3 +1 @@
.vscode .vscode
node_modules/
.DS_Store

View file

@ -14,8 +14,6 @@ Before you start you should have a few things installed on your machine:
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. 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.
**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.
The first exercise, `helloWorld`, will walk you through the process in-depth. The first exercise, `helloWorld`, will walk you through the process in-depth.
## Solutions ## Solutions

View file

@ -1,6 +1,6 @@
# Exercise 13 - Caesar cipher # Exercise XX - caesar cipher
Implement the legendary Caesar cipher: Implement the legendary caesar cipher:
> 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. > 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.
@ -31,3 +31,5 @@ negative numbers should work as well:
```javascript ```javascript
caesar('Mjqqt, Btwqi!', -5) // returns 'Hello, World!' caesar('Mjqqt, Btwqi!', -5) // returns 'Hello, World!'
``` ```

View file

@ -1,5 +1,5 @@
const caesar = function() { const caesar = function() {
}; }
module.exports = caesar; module.exports = caesar

View file

@ -1,8 +1,6 @@
# Exercise 08 - Calculator
The goal for this exercise is to create a calculator that does the following: The goal for this exercise is to create a calculator that does the following:
add, subtract, get the sum, multiply, get the power, and find the factorial add, subtract, get the sum, multiply, get the power, and find the factorial
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 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
take a look at the spec file that houses the Jest test cases. take a look at the spec file that houses the Jasmine test cases.

View file

@ -1,26 +1,26 @@
const add = function() { function add () {
}; }
const subtract = function() { function subtract () {
}; }
const sum = function() { function sum () {
}; }
const multiply = function() { function multiply () {
};;
const power = function() {
}; }
const factorial = function() { function power() {
}; }
function factorial() {
}
module.exports = { module.exports = {
add, add,
@ -28,5 +28,5 @@ module.exports = {
sum, sum,
multiply, multiply,
power, power,
factorial factorial,
}; };

View file

@ -1,56 +1,56 @@
const calculator = require('./calculator'); const calculator = require ('./calculator.js');
describe('add', function() { describe('add', function() {
it('adds 0 and 0', function() { it('adds 0 and 0', function() {
expect(calculator.add(0,0)).toEqual(0); expect(calculator.add(0,0)).toEqual(0);
}); });
test.skip('adds 2 and 2', () => { xit('adds 2 and 2', function() {
expect(calculator.add(2,2)).toBe(4); expect(calculator.add(2,2)).toEqual(4);
}); });
test.skip('adds positive numbers', () => { xit('adds positive numbers', function() {
expect(calculator.add(2,6)).toBe(8); expect(calculator.add(2,6)).toEqual(8);
}); });
}); });
describe('subtract', () => { describe('subtract', function() {
test.skip('subtracts numbers', () => { xit('subtracts numbers', function() {
expect(calculator.subtract(10,4)).toBe(6); expect(calculator.subtract(10,4)).toEqual(6);
}); });
}); });
describe('sum', () => { describe('sum', function() {
test.skip('computes the sum of an empty array', () => { xit('computes the sum of an empty array', function() {
expect(calculator.sum([])).toBe(0); expect(calculator.sum([])).toEqual(0);
}); });
test.skip('computes the sum of an array of one number', () => { xit('computes the sum of an array of one number', function() {
expect(calculator.sum([7])).toBe(7); expect(calculator.sum([7])).toEqual(7);
}); });
test.skip('computes the sum of an array of two numbers', () => { xit('computes the sum of an array of two numbers', function() {
expect(calculator.sum([7,11])).toBe(18); expect(calculator.sum([7,11])).toEqual(18);
}); });
test.skip('computes the sum of an array of many numbers', () => { xit('computes the sum of an array of many numbers', function() {
expect(calculator.sum([1,3,5,7,9])).toBe(25); expect(calculator.sum([1,3,5,7,9])).toEqual(25);
}); });
}); });
describe('multiply', () => { describe('multiply', function() {
test.skip('multiplies two numbers', () => { xit('multiplies two numbers', function() {
expect(calculator.multiply([2,4])).toBe(8); expect(calculator.multiply([2,4])).toEqual(8);
}); });
test.skip('multiplies several numbers', () => { xit('multiplies several numbers', function() {
expect(calculator.multiply([2,4,6,8,10,12,14])).toBe(645120); expect(calculator.multiply([2,4,6,8,10,12,14])).toEqual(645120);
}); });
}); });
describe('power', () => { describe('power', function() {
test.skip('raises one number to the power of another number', () => { xit('raises one number to the power of another number', function() {
expect(calculator.power(4,3)).toBe(64); // 4 to third power is 64 expect(calculator.power(4,3)).toEqual(64); // 4 to third power is 64
}); });
}); });

View file

@ -1,8 +1,8 @@
# Exercise 10 - Fibonacci # Exercise XX - fibonacci
Create a function that returns a specific member of the Fibonacci sequence: Create a function that returns a specific member of the fibonacci sequence:
> 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. > 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.
```javascript ```javascript
fibonacci(4) // returns the 4th member of the series: 3 (1, 1, 2, 3) fibonacci(4) // returns the 4th member of the series: 3 (1, 1, 2, 3)

View file

@ -1,3 +1,3 @@
const fibonacci = function () {}; const fibonacci = function () {};
}; module.exports = fibonacci

View file

@ -1,8 +1,9 @@
# Exercise 12 - Find the Oldest # Find the Oldest
Given an array of objects representing people with a birth and death year, return the oldest person. given an array of objects representing people with a birth and death year, return the oldest person.
## Hints ## Hints
- You should return the whole person object, but the tests mostly just check to make sure the name is correct. - You should return the whole person object, but the tests mostly just check to make sure the name is correct.
- this can be done with a couple of chained array methods, or by using `reduce`. - this can be done with a couple of chained array methods, or by using `reduce`.
- One of the tests checks for people with no death-date.. use JavaScript's Date function to get their age as of today. - One of the tests checks for people with no death-date.. use JavaScript's Date function to get their age as of today.

View file

@ -1,5 +1,3 @@
const findTheOldest = function() { let findTheOldest = function() {
}
};
module.exports = findTheOldest; module.exports = findTheOldest;

View file

@ -1,5 +1,5 @@
let <%= title %> = function() { let <%= title %> = function() {
}; }
module.exports = <%= title %>; module.exports = <%= title %>

View file

@ -1,7 +1,7 @@
let <%= title %> = require('./<%=title%>') let <%= title %> = require('./<%=title%>')
describe('<%=title%>', function() { describe('<%=title%>', function() {
test('EDITME', function() { it('EDITME', function() {
expect(<%=title%>()).toEqual(' '); expect(<%=title%>()).toEqual(' ');
}); });

View file

@ -1,4 +1,4 @@
# Exercise 11 - Get the Titles! # Get the Titles!
You are given an array of objects that represent books with an author and a title that looks like this: You are given an array of objects that represent books with an author and a title that looks like this:
@ -15,7 +15,7 @@ const books = [
] ]
``` ```
Your job is to write a function that takes the array and returns an array of titles: your job is to write a function that takes the array and returns an array of titles:
```javascript ```javascript
getTheTitles(books) // ['Book','Book2'] getTheTitles(books) // ['Book','Book2']

View file

@ -1,5 +1,5 @@
const getTheTitles = function() { const getTheTitles = function() {
}; }
module.exports = getTheTitles; module.exports = getTheTitles;

View file

@ -12,7 +12,7 @@ describe('getTheTitles', function() {
} }
] ]
test('gets titles', () => { it('gets titles', function() {
expect(getTheTitles(books)).toEqual(['Book','Book2']); expect(getTheTitles(books)).toEqual(['Book','Book2']);
}); });
}); });

View file

@ -1,4 +1,4 @@
# Exercise 01 - Hello World # Exercise 01 - Hello World.
The main purpose of this exercise is to walk you through the process of running the tests and make sure everything is set up and running correctly. The main purpose of this exercise is to walk you through the process of running the tests and make sure everything is set up and running correctly.
@ -13,16 +13,16 @@ Let's look at the spec file first:
const helloWorld = require('./helloWorld'); const helloWorld = require('./helloWorld');
describe('Hello World', function() { describe('Hello World', function() {
test('says hello world', function() { it('says hello world', function() {
expect(helloWorld()).toEqual('Hello, World!'); expect(helloWorld()).toEqual('Hello, World!');
}); });
}); });
``` ```
At the very top of the file we use `require()` to import the code from the javascript file (`helloWorld.js`) so that we can test it. At the very top of the file we use `require()` to import the code from the javascript file (`helloWorld.js`) so that we can test it.
The next block (`describe()`) is the body of the test. Basically, all it's doing is running your code and testing to see if the output is correct. The `test()` function describes what should be happening in plain english and then includes the `expect()` function. For this simple example it should be pretty simple to read. The next block (`describe()`) is the body of the test. Basically, all it's doing is running your code and testing to see if the output is correct. The `it()` function describes what should be happening in plain english and then includes the `expect()` function. For this simple example it should be pretty simple to read.
For now you do not need to worry about how to write tests, but you should try to get comfortable enough with the syntax to figure out what the tests are asking you to do. Go ahead and run the tests by entering `npm test helloWorld.spec.js` in the terminal and watch it fail. The output from that command should tell you exactly what went wrong with your code. In this case, running the `helloWorld()` function should return the phrase 'Hello, World!' but instead it returns an empty string... For now you do not need to worry about how to write tests, but you should try to get comfortable enough with the syntax to figure out what the tests are asking you to do. Go ahead and run the tests by entering `jasmine helloWorld.spec.js` in the terminal and watch it fail. The output from that command should tell you exactly what went wrong with your code. In this case, running the `helloWorld()` function should return the phrase 'Hello, World!' but instead it returns an empty string...
so let's look at the javascript file: so let's look at the javascript file:
```javascript ```javascript

View file

@ -1,4 +1,4 @@
# Exercise 06 - leapYears # Exercise XX - leapYears
Create a function that determines whether or not a given year is a leap year. Leap years are determined by the following rules: Create a function that determines whether or not a given year is a leap year. Leap years are determined by the following rules:

View file

@ -1,5 +1,5 @@
const leapYears = function() { const leapYears = function() {
}; }
module.exports = leapYears; module.exports = leapYears

5905
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,29 +0,0 @@
{
"name": "javascript-exercises",
"version": "1.0.0",
"description": "These are a series of javascript exercises intended to be used alongside the curriculum at 'The Odin Project' They start off nice and easy, but get more involved as you progress through them.",
"main": "index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/TheOdinProject/javascript-exercises.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/TheOdinProject/javascript-exercises/issues"
},
"homepage": "https://github.com/TheOdinProject/javascript-exercises#readme",
"devDependencies": {
"jest": "^26.6.3",
"jest-cli": "^26.6.3",
"eslint": "^7.26.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.22.1"
},
"scripts": {
"test": "jest"
},
"eslintConfig": {
"root": true
}
}

View file

@ -1,4 +1,4 @@
# Exercise 09 - Palindromes # Exercise XX - palindromes
Write a function that determines whether or not a given string is a palindrome. Write a function that determines whether or not a given string is a palindrome.

View file

@ -1,5 +1,4 @@
const palindromes = function () {}; const palindromes = function () {};
};
module.exports = palindromes module.exports = palindromes

View file

@ -1,5 +0,0 @@
function pigLatin(string) {
};
module.exports = pigLatin;

View file

@ -1,56 +0,0 @@
const pigLatin = require('./pigLatin')
// Topics
// * modules
// * strings
// Pig Latin
// 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.
// Rule 1: If a word begins with a vowel sound, add an "ay" sound to the end of the word.
// 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.
// (There are a few more rules for edge cases, and there are regional variants too, but that should be enough to understand the tests.)
// See https://en.wikipedia.org/wiki/Pig_Latin for more details.
describe('translate', () => {
test('translates a word beginning with a vowel', () => {
expect(pigLatin("apple")).toBe('appleay');
});
test.skip('translates a word beginning with a consonant', () => {
expect(pigLatin("banana")).toBe("ananabay");
});
test.skip('translates a word beginning with two consonants', () => {
expect(pigLatin("cherry")).toBe('errychay');
});
test.skip('translates two words', () => {
expect(pigLatin("eat pie")).toBe('eatay iepay');
});
test.skip('translates a word beginning with three consonants', () => {
expect(pigLatin("three")).toBe("eethray");
});
test.skip('counts "sch" as a single phoneme', () => {
expect(pigLatin("school")).toBe("oolschay");
});
test.skip('counts "qu" as a single phoneme', () => {
expect(pigLatin("quiet")).toBe("ietquay");
});
test.skip('counts "qu" as a consonant even when its preceded by a consonant', () => {
expect(pigLatin("square")).toBe("aresquay");
});
test.skip('translates many words', () => {
expect(pigLatin("the quick brown fox")).toBe("ethay ickquay ownbray oxfay");
});
});

View file

@ -0,0 +1,64 @@
// Topics
// * modules
// * strings
// Pig Latin
// 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.
// Rule 1: If a word begins with a vowel sound, add an "ay" sound to the end of the word.
// 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.
// (There are a few more rules for edge cases, and there are regional variants too, but that should be enough to understand the tests.)
// See https://en.wikipedia.org/wiki/Pig_Latin for more details.
const pigLatin = require("./pigLatin.js");
describe('#translate', function() {
it('translates a word beginning with a vowel', function() {
s = pigLatin.translate("apple");
expect(s).toEqual('appleay');
});
xit('translates a word beginning with a consonant', function() {
s = pigLatin.translate("banana");
expect(s).toEqual("ananabay");
});
xit('translates a word beginning with two consonants', function() {
s = pigLatin.translate("cherry");
expect(s).toEqual('errychay');
});
xit('translates two words', function() {
s = pigLatin.translate("eat pie");
expect(s).toEqual('eatay iepay');
});
xit('translates a word beginning with three consonants', function() {
expect(pigLatin.translate("three")).toEqual("eethray");
});
xit('counts "sch" as a single phoneme', function() {
s = pigLatin.translate("school");
expect(s).toEqual("oolschay");
});
xit('counts "qu" as a single phoneme', function() {
s = pigLatin.translate("quiet");
expect(s).toEqual("ietquay");
});
xit('counts "qu" as a consonant even when its preceded by a consonant', function() {
s = pigLatin.translate("square");
expect(s).toEqual("aresquay");
});
xit('translates many words', function() {
s = pigLatin.translate("the quick brown fox");
expect(s).toEqual("ethay ickquay ownbray oxfay");
});
});

View file

@ -8,9 +8,10 @@ removeFromArray([1, 2, 3, 4], 3); // should remove 3 and return [1,2,4]
## Hints ## Hints
The first test on this one is fairly easy, but there are a few things to think about(or google) here for the later tests: the first test on this one is fairly easy, but there are a few things to think about(or google) here for the later tests:
- how to remove a single element from an array - how to remove a single element from an array
- how to deal with multiple optional arguments in a javascript function - how to deal with multiple optional arguments in a javascript function
- [Check this link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments). Scroll down to the bit about `Array.from` or the spread operator. - [Or this link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters). - [Check this link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments). Scroll down to the bit about `Array.from` or the spread operator. - [Or this link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters).

View file

@ -1,5 +1,5 @@
const removeFromArray = function() { const removeFromArray = function() {
}; }
module.exports = removeFromArray; module.exports = removeFromArray

View file

@ -1,25 +1,25 @@
const removeFromArray = require('./removeFromArray') const removeFromArray = require('./removeFromArray')
describe('removeFromArray', () => { describe('removeFromArray', function() {
test('removes a single value', () => { it('removes a single value', function() {
expect(removeFromArray([1, 2, 3, 4], 3)).toEqual([1, 2, 4]); expect(removeFromArray([1, 2, 3, 4], 3)).toEqual([1, 2, 4]);
}); });
test.skip('removes multiple values', () => { xit('removes multiple values', function() {
expect(removeFromArray([1, 2, 3, 4], 3, 2)).toEqual([1, 4]); expect(removeFromArray([1, 2, 3, 4], 3, 2)).toEqual([1, 4]);
}); });
test.skip('ignores non present values', () => { xit('ignores non present values', function() {
expect(removeFromArray([1, 2, 3, 4], 7, "tacos")).toEqual([1, 2, 3, 4]); expect(removeFromArray([1, 2, 3, 4], 7, "tacos")).toEqual([1, 2, 3, 4]);
}); });
test.skip('ignores non present values, but still works', () => { xit('ignores non present values, but still works', function() {
expect(removeFromArray([1, 2, 3, 4], 7, 2)).toEqual([1, 3, 4]); expect(removeFromArray([1, 2, 3, 4], 7, 2)).toEqual([1, 3, 4]);
}); });
test.skip('can remove all values', () => { xit('can remove all values', function() {
expect(removeFromArray([1, 2, 3, 4], 1, 2, 3, 4)).toEqual([]); expect(removeFromArray([1, 2, 3, 4], 1, 2, 3, 4)).toEqual([]);
}); });
test.skip('works with strings', () => { xit('works with strings', function() {
expect(removeFromArray(["hey", 2, 3, "ho"], "hey", 3)).toEqual([2, "ho"]); expect(removeFromArray(["hey", 2, 3, "ho"], "hey", 3)).toEqual([2, "ho"]);
}); });
test.skip('only removes same type', () => { xit('only removes same type', function() {
expect(removeFromArray([1, 2, 3], "1", 3)).toEqual([1, 2]); expect(removeFromArray([1, 2, 3], "1", 3)).toEqual([1, 2]);
}); });
}); });

View file

@ -6,7 +6,7 @@ Write a function that simply repeats the string a given number of times:
repeatString('hey', 3) // returns 'heyheyhey' repeatString('hey', 3) // returns 'heyheyhey'
``` ```
You will notice in this exercise that there are multiple tests (see in file `repeatString.spec.js`). Only the first test is currently enabled. So after making sure that this first one passes, enable the others one by one by deleting the `.skip` from the `test.skip()` function. You will notice in this exercise that there are multiple tests (see in file `repeatString.spec.js`). Only the first test is currently enabled. So after making sure that this first one passes, enable the others one by one by deleting the `x` in front of the `it()` function.
## Hints ## Hints
@ -15,11 +15,4 @@ You will notice in this exercise that there are multiple tests (see in file `rep
- Create a variable to hold the string you're going to return, create a loop that repeats the given number of times and add the given string to the result on each loop. - Create a variable to hold the string you're going to return, create a loop that repeats the given number of times and add the given string to the result on each loop.
- If running `npm test repeatString.spec.js` returns results similar to the below: - If running `jasmine repeatString.spec.js` raises `Temporarily disabled with xit` errors, make sure you have enabled the rest of the tests (see above).
```
Test Suites: 1 passed, 1 total
Tests: 6 skipped, 1 passed, 7 total
```
- Make sure you have enabled the rest of the tests (see above).

View file

@ -1,5 +1,5 @@
const repeatString = function() { const repeatString = function() {
}; }
module.exports = repeatString; module.exports = repeatString

View file

@ -1,22 +1,22 @@
const repeatString = require('./repeatString') const repeatString = require('./repeatString')
describe('repeatString', () => { describe('repeatString', function() {
test('repeats the string', () => { it('repeats the string', function() {
expect(repeatString('hey', 3)).toEqual('heyheyhey'); expect(repeatString('hey', 3)).toEqual('heyheyhey');
}); });
test.skip('repeats the string many times', () => { xit('repeats the string many times', function() {
expect(repeatString('hey', 10)).toEqual('heyheyheyheyheyheyheyheyheyhey'); expect(repeatString('hey', 10)).toEqual('heyheyheyheyheyheyheyheyheyhey');
}); });
test.skip('repeats the string 1 times', () => { xit('repeats the string 1 times', function() {
expect(repeatString('hey', 1)).toEqual('hey'); expect(repeatString('hey', 1)).toEqual('hey');
}); });
test.skip('repeats the string 0 times', () => { xit('repeats the string 0 times', function() {
expect(repeatString('hey', 0)).toEqual(''); expect(repeatString('hey', 0)).toEqual('');
}); });
test.skip('returns ERROR with negative numbers', () => { xit('returns ERROR with negative numbers', function() {
expect(repeatString('hey', -1)).toEqual('ERROR'); expect(repeatString('hey', -1)).toEqual('ERROR');
}); });
test.skip('repeats the string a random amount of times', function () { xit('repeats the string a random amount of times', function () {
/*The number is generated by using Math.random to get a value from between /*The number is generated by using Math.random to get a value from between
0 to 1, when this is multiplied by 1000 and rounded down with Math.floor it 0 to 1, when this is multiplied by 1000 and rounded down with Math.floor it
equals a number between 0 to 999 (this number will change everytime you run equals a number between 0 to 999 (this number will change everytime you run
@ -31,7 +31,7 @@ describe('repeatString', () => {
was randomaly generated. */ was randomaly generated. */
expect(repeatString('hey', number).match(/((hey))/g).length).toEqual(number); expect(repeatString('hey', number).match(/((hey))/g).length).toEqual(number);
}); });
test.skip('works with blank strings', () => { xit('works with blank strings', function() {
expect(repeatString('', 10)).toEqual(''); expect(repeatString('', 10)).toEqual('');
}); });
}); });

View file

@ -1,4 +1,4 @@
# Exercise 03 - Reverse a String # Exercise 03 - Reverse a String.
Pretty simple, write a function called `reverseString` that returns its input, reversed! Pretty simple, write a function called `reverseString` that returns its input, reversed!
@ -6,7 +6,10 @@ Pretty simple, write a function called `reverseString` that returns its input, r
reverseString('hello there') // returns 'ereht olleh' reverseString('hello there') // returns 'ereht olleh'
``` ```
You will notice in this exercise that there are multiple tests, after making the first one pass, enable the others one by one by deleting the `.skip` in front the `test.skip()` function. You will notice in this exercise that there are multiple tests, after making the first one pass, enable the others one by one by deleting the `x` in front of the `it()` function.
## Hints ## Hints
Strings in JavaScript cannot be reversed directly so you're going to have to split it into something else first.. do the reversal and then join it back together into a string. Strings in JavaScript cannot be reversed directly so you're going to have to split it into something else first.. do the reversal and then join it back together into a string.

View file

@ -1,5 +1,5 @@
const reverseString = function() { const reverseString = function() {
}; }
module.exports = reverseString; module.exports = reverseString

View file

@ -1,18 +1,18 @@
const reverseString = require('./reverseString') const reverseString = require('./reverseString')
describe('reverseString', () => { describe('reverseString', function() {
test('reverses single word', () => { it('reverses single word', function() {
expect(reverseString('hello')).toEqual('olleh'); expect(reverseString('hello')).toEqual('olleh');
}); });
test.skip('reverses multiple words', () => { xit('reverses multiple words', function() {
expect(reverseString('hello there')).toEqual('ereht olleh') expect(reverseString('hello there')).toEqual('ereht olleh')
}) })
test.skip('works with numbers and punctuation', () => { xit('works with numbers and punctuation', function() {
expect(reverseString('123! abc!')).toEqual('!cba !321') expect(reverseString('123! abc!')).toEqual('!cba !321')
}) })
test.skip('works with blank strings', () => { xit('works with blank strings', function() {
expect(reverseString('')).toEqual('') expect(reverseString('')).toEqual('')
}) })
}); });

View file

@ -1,5 +1,5 @@
const snakeCase = function() { const snakeCase = function() {
}; }
module.exports = snakeCase; module.exports = snakeCase

View file

@ -1,22 +1,26 @@
const snakeCase = require('./snakeCase') const snakeCase = require('./snakeCase')
describe('snakeCase', () => { describe("snakeCase", function () {
test('works with simple lowercased phrases', () => { it("works with simple lowercased phrases", function () {
expect(snakeCase('hello world')).toEqual('hello_world'); expect(snakeCase("hello world")).toEqual("hello_world");
}); });
test.skip('works with Caps and punctuation', () => { xit("works with Caps and punctuation", function () {
expect(snakeCase('Hello, World???')).toEqual('hello_world'); expect(snakeCase("Hello, World???")).toEqual("hello_world");
}); });
test.skip('works with longer phrases', () => { xit("works with longer phrases", function () {
expect(snakeCase('This is the song that never ends....')).toEqual('this_is_the_song_that_never_ends'); expect(snakeCase("This is the song that never ends....")).toEqual(
"this_is_the_song_that_never_ends"
);
}); });
test.skip('works with camel case', () => { xit("works with camel case", function () {
expect(snakeCase('snakeCase')).toEqual('snake_case'); expect(snakeCase("snakeCase")).toEqual("snake_case");
}); });
test.skip('works with kebab case', () => { xit("works with kebab case", function () {
expect(snakeCase('snake-case')).toEqual('snake_case'); expect(snakeCase("snake-case")).toEqual("snake_case");
}); });
test.skip('works with WTF case', () => { xit("works with WTF case", function () {
expect(snakeCase('SnAkE..CaSe..Is..AwEsOmE')).toEqual('snake_case_is_awesome'); expect(snakeCase("SnAkE..CaSe..Is..AwEsOmE")).toEqual(
"snake_case_is_awesome"
);
}); });
}); });

View file

@ -1,5 +1,5 @@
const sumAll = function() { const sumAll = function() {
}; }
module.exports = sumAll; module.exports = sumAll

View file

@ -1,22 +1,22 @@
const sumAll = require('./sumAll') const sumAll = require('./sumAll')
describe('sumAll', () => { describe("sumAll", function () {
test('sums numbers within the range', () => { it("sums numbers within the range", function () {
expect(sumAll(1, 4)).toEqual(10); expect(sumAll(1, 4)).toEqual(10);
}); });
test.skip('works with large numbers', () => { xit("works with large numbers", function () {
expect(sumAll(1, 4000)).toEqual(8002000); expect(sumAll(1, 4000)).toEqual(8002000);
}); });
test.skip('works with larger number first', () => { xit("works with larger number first", function () {
expect(sumAll(123, 1)).toEqual(7626); expect(sumAll(123, 1)).toEqual(7626);
}); });
test.skip('returns ERROR with negative numbers', () => { xit("returns ERROR with negative numbers", function () {
expect(sumAll(-10, 4)).toEqual('ERROR'); expect(sumAll(-10, 4)).toEqual("ERROR");
}); });
test.skip('returns ERROR with non-number parameters', () => { xit("returns ERROR with non-number parameters", function () {
expect(sumAll(10, "90")).toEqual('ERROR'); expect(sumAll(10, "90")).toEqual("ERROR");
}); });
test.skip('returns ERROR with non-number parameters', () => { xit("returns ERROR with non-number parameters", function () {
expect(sumAll(10, [90, 1])).toEqual('ERROR'); expect(sumAll(10, [90, 1])).toEqual("ERROR");
}); });
}); });

View file

@ -1,4 +1,4 @@
# Exercise 07 - tempConversion # Exercise 06 - tempConversion
Write two functions that convert temperatures from Fahrenheit to Celsius, and vice versa: Write two functions that convert temperatures from Fahrenheit to Celsius, and vice versa:
``` ```

View file

@ -1,12 +1,12 @@
const ftoc = function() { const ftoc = function() {
}; }
const ctof = function() { const ctof = function() {
}; }
module.exports = { module.exports = {
ftoc, ftoc,
ctof ctof
}; }

View file

@ -1,25 +1,25 @@
const {ftoc, ctof} = require('./tempConversion') const {ftoc, ctof} = require('./tempConversion')
describe('ftoc', () => { describe('ftoc', function() {
test('works', () => { it('works', function() {
expect(ftoc(32)).toEqual(0); expect(ftoc(32)).toEqual(0);
}); });
test.skip('rounds to 1 decimal', () => { xit('rounds to 1 decimal', function() {
expect(ftoc(100)).toEqual(37.8); expect(ftoc(100)).toEqual(37.8);
}); });
test.skip('works with negatives', () => { xit('works with negatives', function() {
expect(ftoc(-100)).toEqual(-73.3); expect(ftoc(-100)).toEqual(-73.3);
}); });
}); });
describe('ctof', () => { describe('ctof', function() {
test.skip('works', () => { xit('works', function() {
expect(ctof(0)).toEqual(32); expect(ctof(0)).toEqual(32);
}); });
test.skip('rounds to 1 decimal', () => { xit('rounds to 1 decimal', function() {
expect(ctof(73.2)).toEqual(163.8); expect(ctof(73.2)).toEqual(163.8);
}); });
test.skip('works with negatives', () => { xit('works with negatives', function() {
expect(ctof(-10)).toEqual(14); expect(ctof(-10)).toEqual(14);
}); });
}); });