added trailing semicolon to all function and module exports
This commit is contained in:
parent
58d2eb108a
commit
2f63b3e380
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"extends": "airbnb-base",
|
||||
"plugins": [
|
||||
"import"
|
||||
],
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 12,
|
||||
"sourceType": "module"
|
||||
},
|
||||
"rules": {
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
# Exercise XX - 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.
|
||||
|
||||
|
@ -31,5 +31,3 @@ negative numbers should work as well:
|
|||
```javascript
|
||||
caesar('Mjqqt, Btwqi!', -5) // returns 'Hello, World!'
|
||||
```
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const caesar = function() {
|
||||
|
||||
}
|
||||
};;
|
||||
|
||||
module.exports = caesar
|
||||
module.exports = caesar;
|
||||
|
|
|
@ -2,5 +2,5 @@ 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
|
||||
|
||||
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 Jasmine test cases.
|
||||
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
|
||||
take a look at the spec file that houses the Jest test cases.
|
|
@ -1,26 +1,26 @@
|
|||
const add = function() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
const subtract = function() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
const sum = function() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
const multiply = function() {
|
||||
|
||||
}
|
||||
};;
|
||||
|
||||
const power = function() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
const factorial = function() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
add,
|
||||
|
@ -29,4 +29,4 @@ module.exports = {
|
|||
multiply,
|
||||
power,
|
||||
factorial
|
||||
}
|
||||
};
|
|
@ -1,55 +1,55 @@
|
|||
const calculator = require ('./calculator.js');
|
||||
const calculator = require('./calculator');
|
||||
|
||||
describe('add', () => {
|
||||
test('adds 0 and 0', () => {
|
||||
expect(calculator.add(0,0)).toBe(0);
|
||||
});
|
||||
|
||||
test('adds 2 and 2', () => {
|
||||
test.skip('adds 2 and 2', () => {
|
||||
expect(calculator.add(2,2)).toBe(4);
|
||||
});
|
||||
|
||||
test('adds positive numbers', () => {
|
||||
test.skip('adds positive numbers', () => {
|
||||
expect(calculator.add(2,6)).toBe(8);
|
||||
});
|
||||
});
|
||||
|
||||
describe('subtract', () => {
|
||||
test('subtracts numbers', () => {
|
||||
test.skip('subtracts numbers', () => {
|
||||
expect(calculator.subtract(10,4)).toBe(6);
|
||||
});
|
||||
});
|
||||
|
||||
describe('sum', () => {
|
||||
test('computes the sum of an empty array', () => {
|
||||
test.skip('computes the sum of an empty array', () => {
|
||||
expect(calculator.sum([])).toBe(0);
|
||||
});
|
||||
|
||||
test('computes the sum of an array of one number', () => {
|
||||
test.skip('computes the sum of an array of one number', () => {
|
||||
expect(calculator.sum([7])).toBe(7);
|
||||
});
|
||||
|
||||
test('computes the sum of an array of two numbers', () => {
|
||||
test.skip('computes the sum of an array of two numbers', () => {
|
||||
expect(calculator.sum([7,11])).toBe(18);
|
||||
});
|
||||
|
||||
test('computes the sum of an array of many numbers', () => {
|
||||
test.skip('computes the sum of an array of many numbers', () => {
|
||||
expect(calculator.sum([1,3,5,7,9])).toBe(25);
|
||||
});
|
||||
});
|
||||
|
||||
describe('multiply', () => {
|
||||
test('multiplies two numbers', () => {
|
||||
test.skip('multiplies two numbers', () => {
|
||||
expect(calculator.multiply([2,4])).toBe(8);
|
||||
});
|
||||
|
||||
test('multiplies several numbers', () => {
|
||||
test.skip('multiplies several numbers', () => {
|
||||
expect(calculator.multiply([2,4,6,8,10,12,14])).toBe(645120);
|
||||
});
|
||||
});
|
||||
|
||||
describe('power', () => {
|
||||
test('raises one number to the power of another number', () => {
|
||||
test.skip('raises one number to the power of another number', () => {
|
||||
expect(calculator.power(4,3)).toBe(64); // 4 to third power is 64
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
# Exercise XX - 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
|
||||
fibonacci(4) // returns the 4th member of the series: 3 (1, 1, 2, 3)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const fibonacci = function() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = fibonacci;
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
# 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
|
||||
- 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`.
|
||||
- One of the tests checks for people with no death-date.. use JavaScript's Date function to get their age as of today.
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const findTheOldest = function() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = findTheOldest
|
||||
module.exports = findTheOldest;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
let <%= title %> = function() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = <%= title %>
|
||||
module.exports = <%= title %>;
|
||||
|
|
|
@ -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
|
||||
getTheTitles(books) // ['Book','Book2']
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const getTheTitles = function() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = getTheTitles;
|
||||
|
|
|
@ -13,7 +13,7 @@ describe('getTheTitles', () => {
|
|||
]
|
||||
|
||||
test('gets titles', () => {
|
||||
expect(getTheTitles(books)).toBe(['Book','Book2']);
|
||||
expect(getTheTitles(books)).toEqual(['Book','Book2']);
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -6,7 +6,7 @@ In this directory you will find 2 other files:
|
|||
1. `helloWorld.js`
|
||||
2. `helloWorld.spec.js`
|
||||
|
||||
This setup should be the same for all of the exercises. The plain javascript file is where you'll write your code, and the `spec` file contains the tests that verify your code is functional.
|
||||
This setup should be the same for all of the exercises. The plain javascript file is where you'll write your code, and the `spec` file contains the tests that verify your code is functional.
|
||||
|
||||
Let's look at the spec file first:
|
||||
```javascript
|
||||
|
@ -20,9 +20,9 @@ describe('Hello World', function() {
|
|||
```
|
||||
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 `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.
|
||||
|
||||
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...
|
||||
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...
|
||||
|
||||
so let's look at the javascript file:
|
||||
```javascript
|
||||
|
@ -30,13 +30,13 @@ const helloWorld = function() {
|
|||
return ''
|
||||
}
|
||||
|
||||
module.exports = helloWorld;
|
||||
module.exports = helloWorld
|
||||
```
|
||||
In this file we have a simple function called helloWorld that returns an empty string... which is exactly what our test was complaining about. The `module.exports` on the last line is how we export the function so that it can be imported with `require()` in the spec file.
|
||||
In this file we have a simple function called helloWorld that returns an empty string... which is exactly what our test was complaining about. The `module.exports` on the last line is how we export the function so that it can be imported with `require()` in the spec file.
|
||||
|
||||
Go ahead and see if you can make the test pass by editing the return value of the function, and then running the test file again.
|
||||
|
||||
Just to make sure, in case you're confused at this point, the test is telling you that running the function `helloWorld` should return the phrase `Hello, World!`. Punctuation and capitalization definitely matter here, so double check that if the test still isn't passing.
|
||||
Just to make sure, in case you're confused at this point, the test is telling you that running the function `helloWorld` should return the phrase `Hello, World!`. Punctuation and capitalization definitely matter here, so double check that if the test still isn't passing.
|
||||
|
||||
this is what the final function should look like:
|
||||
```javascript
|
||||
|
@ -44,7 +44,7 @@ const helloWorld = function() {
|
|||
return 'Hello, World!'
|
||||
}
|
||||
|
||||
module.exports = helloWorld;
|
||||
module.exports = helloWorld
|
||||
```
|
||||
|
||||
For the most part we've set up these tests in such a way that you only have to write the code being tested. You should not have to worry about importing or exporting anything at this stage, so just work around that bit of the code and write what it takes to make them pass!
|
||||
For the most part we've set up these tests in such a way that you only have to write the code being tested. You should not have to worry about importing or exporting anything at this stage.. so just work around that bit of the code and write what it takes to make them pass!
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const leapYears = function() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = leapYears
|
||||
module.exports = leapYears;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
22
package.json
22
package.json
|
@ -1,9 +1,27 @@
|
|||
{
|
||||
"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 very simply, 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"
|
||||
"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"
|
||||
"test": "jest",
|
||||
"lint" : "./node_modules/.bin/eslint"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const palindromes = function() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = palindromes;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
function pigLatin(string) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = pigLatin
|
||||
module.exports = pigLatin;
|
|
@ -19,38 +19,38 @@ const pigLatin = require('./pigLatin')
|
|||
|
||||
describe('translate', () => {
|
||||
test('translates a word beginning with a vowel', () => {
|
||||
expect(pigLatin.translate("apple")).toBe('appleay');
|
||||
expect(pigLatin("apple")).toBe('appleay');
|
||||
});
|
||||
|
||||
test.skip('translates a word beginning with a consonant', () => {
|
||||
expect(pigLatin.translate("banana")).toBe("ananabay");
|
||||
expect(pigLatin("banana")).toBe("ananabay");
|
||||
});
|
||||
|
||||
test.skip('translates a word beginning with two consonants', () => {
|
||||
expect(pigLatin.translate("cherry")).toBe('errychay');
|
||||
expect(pigLatin("cherry")).toBe('errychay');
|
||||
});
|
||||
|
||||
test.skip('translates two words', () => {
|
||||
expect(pigLatin.translate("eat pie")).toBe('eatay iepay');
|
||||
expect(pigLatin("eat pie")).toBe('eatay iepay');
|
||||
});
|
||||
|
||||
test.skip('translates a word beginning with three consonants', () => {
|
||||
expect(pigLatin.translate("three")).toBe("eethray");
|
||||
expect(pigLatin("three")).toBe("eethray");
|
||||
});
|
||||
|
||||
test.skip('counts "sch" as a single phoneme', () => {
|
||||
expect(pigLatin.translate("school")).toBe("oolschay");
|
||||
expect(pigLatin("school")).toBe("oolschay");
|
||||
});
|
||||
|
||||
test.skip('counts "qu" as a single phoneme', () => {
|
||||
expect(pigLatin.translate("quiet")).toBe("ietquay");
|
||||
expect(pigLatin("quiet")).toBe("ietquay");
|
||||
});
|
||||
|
||||
test.skip('counts "qu" as a consonant even when its preceded by a consonant', () => {
|
||||
expect(pigLatin.translate("square")).toBe("aresquay");
|
||||
expect(pigLatin("square")).toBe("aresquay");
|
||||
});
|
||||
|
||||
test.skip('translates many words', () => {
|
||||
expect(pigLatin.translate("the quick brown fox")).toBe("ethay ickquay ownbray oxfay");
|
||||
expect(pigLatin("the quick brown fox")).toBe("ethay ickquay ownbray oxfay");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -8,10 +8,9 @@ removeFromArray([1, 2, 3, 4], 3); // should remove 3 and return [1,2,4]
|
|||
|
||||
## 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 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).
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const removeFromArray = function() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = removeFromArray
|
||||
module.exports = removeFromArray;
|
||||
|
|
|
@ -2,24 +2,24 @@ const removeFromArray = require('./removeFromArray')
|
|||
|
||||
describe('removeFromArray', () => {
|
||||
test('removes a single value', () => {
|
||||
expect(removeFromArray([1, 2, 3, 4], 3)).toBe([1, 2, 4]);
|
||||
expect(removeFromArray([1, 2, 3, 4], 3)).toEqual([1, 2, 4]);
|
||||
});
|
||||
test.skip('removes multiple values', () => {
|
||||
expect(removeFromArray([1, 2, 3, 4], 3, 2)).toBe([1, 4]);
|
||||
expect(removeFromArray([1, 2, 3, 4], 3, 2)).toEqual([1, 4]);
|
||||
});
|
||||
test.skip('ignores non present values', () => {
|
||||
expect(removeFromArray([1, 2, 3, 4], 7, "tacos")).toBe([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', () => {
|
||||
expect(removeFromArray([1, 2, 3, 4], 7, 2)).toBe([1, 3, 4]);
|
||||
expect(removeFromArray([1, 2, 3, 4], 7, 2)).toEqual([1, 3, 4]);
|
||||
});
|
||||
test.skip('can remove all values', () => {
|
||||
expect(removeFromArray([1, 2, 3, 4], 1, 2, 3, 4)).toBe([]);
|
||||
expect(removeFromArray([1, 2, 3, 4], 1, 2, 3, 4)).toEqual([]);
|
||||
});
|
||||
test.skip('works with strings', () => {
|
||||
expect(removeFromArray(["hey", 2, 3, "ho"], "hey", 3)).toBe([2, "ho"]);
|
||||
expect(removeFromArray(["hey", 2, 3, "ho"], "hey", 3)).toEqual([2, "ho"]);
|
||||
});
|
||||
test.skip('only removes same type', () => {
|
||||
expect(removeFromArray([1, 2, 3], "1", 3)).toBe([1, 2]);
|
||||
expect(removeFromArray([1, 2, 3], "1", 3)).toEqual([1, 2]);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -15,4 +15,11 @@ 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.
|
||||
|
||||
- If running `jasmine repeatString.spec.js` raises `Temporarily disabled with test.skip` errors, make sure you have enabled the rest of the tests (see above).
|
||||
- If running `npm test repeatString.spec.js` returns results similar to the below:
|
||||
|
||||
```
|
||||
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).
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const repeatString = function() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = repeatString
|
||||
module.exports = repeatString;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const reverseString = function() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = reverseString
|
||||
module.exports = reverseString;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const snakeCase = function() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = snakeCase
|
||||
module.exports = snakeCase;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const sumAll = function() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = sumAll
|
||||
module.exports = sumAll;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
const ftoc = function() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
const ctof = function() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
ftoc,
|
||||
|
|
Loading…
Reference in New Issue