Compare commits
159 Commits
jest-solut
...
main
Author | SHA1 | Date |
---|---|---|
Austin | b8b1ae4eda | |
Alex Younger | a27f66263a | |
Eric Olkowski | a3992aa0de | |
Luis Leiva | 123e00d933 | |
Luis Leiva | 908c4ed26e | |
Jamienorthman | 80ca665767 | |
Miko | 4a03e410bf | |
Miko | 38f0da9643 | |
Austin Sullivan | 157972d135 | |
dependabot[bot] | b469739659 | |
Austin Sullivan | 406b1667aa | |
Miko | e5c0f77d21 | |
Miko | 3b84151724 | |
Miko | 59a2f1ce47 | |
Miko | 5ac1931f72 | |
Miko | f2c0d0955b | |
Brian Lister | bb78d163fc | |
Brian Lister | 59d27bf89f | |
Cody Loyd | 85a9d56fde | |
Carlos Diaz | 7037c2c37c | |
Carlos Diaz | 12f8ffc7e2 | |
Mohd Abbas Haidar | dd7078e1be | |
Manon | dd9a83068d | |
Rushil Jalal | 43a8b165b4 | |
Rushil Jalal | 6d5f678ffc | |
Eric Olkowski | cdba6da97b | |
Will | f5f6efae9b | |
Will | 5513be576a | |
Rushil Jalal | 631d24936b | |
Rushil Jalal | c9ad976fcb | |
01zulfi | 191a43a192 | |
Eric Olkowski | 2ca07161fd | |
Rushil Jalal | c77daf3fa9 | |
Eric Olkowski | 9599e2ade3 | |
Will | 44e39f0412 | |
Will | 1dae9df3ce | |
Will | f855eb51b2 | |
Will | e10ee035ad | |
Austin | e3810865cf | |
Roberra Aklilu | 100f952f7a | |
Roberra Aklilu | e6c4530aa9 | |
01zulfi | 15f1b82b57 | |
Nathan | 51572a070c | |
Austin | f164d790da | |
Nathan | fcb1c4971a | |
Asartea | 051c0ed9ca | |
Asartea | bab1364ea8 | |
cats256 | 76551b0e8a | |
cats256 | 03e52ea9ee | |
cats256 | 075fe8eea2 | |
cats256 | 3ecdab9531 | |
cats256 | 415ff48c20 | |
Manon | 5a7cd9b162 | |
Manon | 37f85db108 | |
Austin | 61c86e11b6 | |
samanyu | f98ee210e0 | |
samanyu | 5c1853e1e9 | |
Cody Loyd | 25013df6ac | |
Cody Loyd | 8692f0ea18 | |
fruddenfeldt | 175ee761e1 | |
Cody Loyd | 6b302e3783 | |
fruddenfeldt | 80f7881a26 | |
fruddenfeldt | b6e9e2fac3 | |
MarLatte | fd1e1f93d1 | |
MarLatte | 0d75cc0814 | |
MarLatte | e8fc8ce41e | |
MarLatte | 41380593f7 | |
MarLatte | 3256f980b0 | |
Eric Olkowski | 3e530e3f61 | |
Eric Olkowski | 6bb8b1397d | |
thatblindgeye | 045f1b0306 | |
Eric Olkowski | 34d63cc59d | |
Ryan McEntire | 197a716eb0 | |
Kevin Mulhern | 029cf3ffcd | |
Kevin Mulhern | 378921289b | |
Kevin Mulhern | cface9db19 | |
Kevin | 736cae8b06 | |
Kevin Mulhern | e63e0bf296 | |
Alex-Nemet | 614b8b8c35 | |
Asartea | 75869d1912 | |
jhylacey | 6f5f71ff5b | |
Kevin Mulhern | ea1f23639c | |
01zulfi | 99d0e8a71a | |
Eric Olkowski | 8dfb7e4508 | |
thatblindgeye | e416717ba9 | |
thatblindgeye | 2ec0f4344d | |
Alex Nemet | 84d537f130 | |
Telcean Marius-Andrei | 83d3dcd1dd | |
Eric Olkowski | a092bf0559 | |
thatblindgeye | 4a112362c8 | |
Eric Olkowski | 8746ce056a | |
Asartea | 9214f20afd | |
Asartea | 0b218347ff | |
Asartea | 374252c302 | |
Rachel Moser | a05d4d60c8 | |
Kevin Mulhern | 0747078d97 | |
Eric Olkowski | 2586a8460c | |
thatblindgeye | fb1a2db8d7 | |
Eric Olkowski | 649f0e3771 | |
Eric Olkowski | f82c72f760 | |
Eric Olkowski | f002e3d6d0 | |
Eric Olkowski | 1971712fde | |
Eric Olkowski | 67d4d0afec | |
Eric Olkowski | 076059551a | |
Eric Olkowski | 2b54b1d682 | |
01zulfi | 2ebbb5a925 | |
Jeremy Myers | edb9c244b5 | |
Eric Olkowski | 417ee0d6e5 | |
Eric Olkowski | baa5b0a761 | |
Eric Olkowski | 6dd594c900 | |
Eric Olkowski | 1b43007a26 | |
Michael Frank | 2f9f431194 | |
Mclilzee | 1acdfccb5d | |
Michael Frank | 82db5eac8b | |
Michael Frank | efdfbd441c | |
Michael Frank | b1a0bf97c3 | |
conor | 7a9377f675 | |
Austin | 10044560cd | |
gerijeb | 09806f109a | |
chagstep1 | 6527372e94 | |
HiddenOgre28 | 36e36b5278 | |
Tatiana | 6b0e0e55e3 | |
Mohammed Sobhi | e4f9675628 | |
Briggs Elsperger | 2197f7b1b5 | |
Briggs Elsperger | 74ab0b7cc6 | |
Tatiana | 0c5601ebd4 | |
Vishant Nambiar | cb083f5511 | |
Tatiana | 137636a425 | |
Mike Esposito | 6274682cb5 | |
Mike Esposito | f0456531e4 | |
Tatiana | 7ec76724d2 | |
davidnth | 702d983059 | |
davidnth | 79e57ddcec | |
Tatiana | 4cdc0d8543 | |
Benjo Kho | 3236ae156c | |
Benjo Kho | 61f38bf60c | |
Benjo Kho | 55cfb173d8 | |
Marvin Gay | ebdc86a349 | |
Marvin Gay | a6298b0c07 | |
Marvin Gay | 3e774830f6 | |
Marvin Gay | d2677eed86 | |
Marvin Gay | b019348daa | |
dependabot[bot] | 67bb819d63 | |
Marvin Gay | 4ec0d5f424 | |
Tatiana | acca175d24 | |
Tatiana | 80affeb2a4 | |
xandora | 9c3bcb49f8 | |
Michael Frank | f8a2928882 | |
Michael Frank | 50ce8d002c | |
xandora | 778096f544 | |
xandora | 6c713cf5f2 | |
xandora | 4355657732 | |
xandora | a2a7813159 | |
xandora | c8857b8221 | |
dependabot[bot] | d3c6a5d061 | |
dependabot[bot] | 76ccc33cc5 | |
dependabot[bot] | 4a220a6d55 | |
dependabot[bot] | cdfa24b1cf | |
dependabot[bot] | b0b57e6d56 |
|
@ -0,0 +1,20 @@
|
|||
version: 2.1
|
||||
|
||||
orbs:
|
||||
node: circleci/node@5.1.0
|
||||
|
||||
jobs:
|
||||
test-solutions:
|
||||
executor: node/default
|
||||
steps:
|
||||
- checkout
|
||||
- node/install-packages:
|
||||
pkg-manager: npm
|
||||
- run:
|
||||
command: npm run test solution
|
||||
name: Run tests in **/solution/*.spec.js
|
||||
|
||||
workflows:
|
||||
test-solutions:
|
||||
jobs:
|
||||
- test-solutions
|
|
@ -0,0 +1,54 @@
|
|||
---
|
||||
name: Bug Report
|
||||
about: Create a report to help us improve something that is not working correctly
|
||||
title: "Bug - :"
|
||||
labels: "Status: Needs Review, Type: Bug"
|
||||
assignees: ""
|
||||
---
|
||||
|
||||
<!-- Thank you for taking the time to submit a bug report to The Odin Project. In order to get issues closed in a reasonable amount of time, you must include a baseline of information about the bug in question. Please read this template in its entirety before filling it out to ensure that it is filled out correctly. -->
|
||||
|
||||
Complete the following REQUIRED checkboxes:
|
||||
- [ ] I have thoroughly read and understand [The Odin Project Contributing Guide](https://github.com/TheOdinProject/.github/blob/main/CONTRIBUTING.md)
|
||||
- [ ] The title of this issue follows the `Bug - location of bug: brief description of bug` format, e.g. `Bug - Exercises: File type incorrect for all test files`
|
||||
|
||||
The following checkbox is OPTIONAL:
|
||||
<!-- Completing this checkbox does not guarantee you will be assigned this issue, but rather lets us know you are interested in working on it. -->
|
||||
- [ ] I would like to be assigned this issue to work on it
|
||||
|
||||
<hr>
|
||||
|
||||
**1. Description of the Bug:**
|
||||
<!-- A clear and concise description of what the bug is. Include any screenshots that may help show the bug in action. -->
|
||||
|
||||
|
||||
**2. How To Reproduce:**
|
||||
<!--
|
||||
What steps one might need to take in order to reproduce this bug, e.g.:
|
||||
1. Log in
|
||||
2. Visit a lesson page
|
||||
3. Click the complete button
|
||||
4. The complete button does not update
|
||||
-->
|
||||
|
||||
|
||||
**3. Expected Behavior:**
|
||||
<!--
|
||||
A brief description of what you expected to happen, e.g.:
|
||||
1. Log in
|
||||
2. Visit a lesson page
|
||||
3. Click the complete button
|
||||
4. The complete button updates correctly
|
||||
-->
|
||||
|
||||
|
||||
**4. Desktop/Device:**
|
||||
<!-- The more information you are able to provide, the better. -->
|
||||
- Device: <!-- [e.g. iPhone6] -->
|
||||
- OS: <!-- [e.g. iOS] -->
|
||||
- Browser: <!-- [e.g. chrome, safari] -->
|
||||
- Version: <!-- [e.g. 22] -->
|
||||
|
||||
**5. Additional Information:**
|
||||
<!-- Any additional information about the bug. -->
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
---
|
||||
name: Feature Request
|
||||
about: Suggest a new feature or enhancement for this project
|
||||
title: ""
|
||||
labels: "Status: Needs Review"
|
||||
assignees: ""
|
||||
---
|
||||
|
||||
<!-- Thank you for taking the time to submit a new feature request to The Odin Project. In order to get issues closed in a reasonable amount of time, you must include a baseline of information about the feature/enhancement you are proposing. Please read this template in its entirety before filling it out to ensure that it is filled out correctly. -->
|
||||
|
||||
Complete the following REQUIRED checkboxes:
|
||||
- [ ] I have thoroughly read and understand [The Odin Project Contributing Guide](https://github.com/TheOdinProject/.github/blob/main/CONTRIBUTING.md)
|
||||
- [ ] The title of this issue follows the `location for request: brief description of request` format, e.g. `Exercises: Add exercise on XYZ`
|
||||
|
||||
The following checkbox is OPTIONAL:
|
||||
<!-- Completing this checkbox does not guarantee you will be assigned this issue, but rather lets us know you are interested in working on it. -->
|
||||
- [ ] I would like to be assigned this issue to work on it
|
||||
|
||||
<hr>
|
||||
|
||||
**1. Description of the Feature Request:**
|
||||
<!--
|
||||
A clear and concise description of what the feature or enhancement is, including how it would be useful/beneficial or what problem(s) it would solve.
|
||||
-->
|
||||
|
||||
|
||||
**2. Acceptance Criteria:**
|
||||
<!--
|
||||
A list of checkbox items that explain the requirements needed to be met to resolve this request, e.g.:
|
||||
- [ ] A theme toggle is present on the dashboard
|
||||
- [ ] Clicking the theme toggle changes between light and dark
|
||||
- [ ] A user's theme choice persists after leaving the website
|
||||
-->
|
||||
|
||||
|
||||
**3. Additional Information:**
|
||||
<!-- Any additional information about the feature request, such as a link to a Discord discussion, screenshots, etc. -->
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<!-- Thank you for taking the time to contribute to The Odin Project. In order to get this pull request (PR) merged in a reasonable amount of time, you must complete this entire template. -->
|
||||
|
||||
## Because
|
||||
<!-- Summarize the purpose or reasons for this PR, e.g. what problem it solves or what benefit it provides. -->
|
||||
|
||||
|
||||
## This PR
|
||||
<!-- A bullet point list of one or more items describing the specific changes. -->
|
||||
|
||||
|
||||
## Issue
|
||||
<!--
|
||||
If this PR closes an open issue in this repo, replace the XXXXX below with the issue number, e.g. Closes #2013.
|
||||
|
||||
If this PR closes an open issue in another TOP repo, replace the #XXXXX with the URL of the issue, e.g. Closes https://github.com/TheOdinProject/curriculum/issues/XXXXX
|
||||
|
||||
If this PR does not close, but is related to another issue or PR, you can link it as above without the 'Closes' keyword, e.g. 'Related to #2013'.
|
||||
-->
|
||||
Closes #XXXXX
|
||||
|
||||
## Additional Information
|
||||
<!-- Any other information about this PR, such as a link to a Discord discussion. -->
|
||||
|
||||
|
||||
## Pull Request Requirements
|
||||
<!-- Replace the whitespace between the square brackets with an 'x', e.g. [x]. After you create the PR, they will become checkboxes that you can click on. -->
|
||||
- [ ] I have thoroughly read and understand [The Odin Project Contributing Guide](https://github.com/TheOdinProject/.github/blob/main/CONTRIBUTING.md)
|
||||
- [ ] The title of this PR follows the `location of change: brief description of change` format, e.g. `01_helloWorld: Update test cases`
|
||||
- [ ] The `Because` section summarizes the reason for this PR
|
||||
- [ ] The `This PR` section has a bullet point list describing the changes in this PR
|
||||
- [ ] If this PR addresses an open issue, it is linked in the `Issue` section
|
||||
- [ ] If this PR includes any changes that affect the solution of an exercise, I've also updated the solution in the `/solutions` folder
|
|
@ -13,7 +13,7 @@ Let's look at the spec file first:
|
|||
const helloWorld = require('./helloWorld');
|
||||
|
||||
describe('Hello World', function() {
|
||||
test('says hello world', function() {
|
||||
test('says "Hello, World!"', function() {
|
||||
expect(helloWorld()).toEqual('Hello, World!');
|
||||
});
|
||||
});
|
||||
|
@ -38,7 +38,7 @@ Go ahead and see if you can make the test pass by editing the return value of th
|
|||
|
||||
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:
|
||||
This is what the final function should look like:
|
||||
```javascript
|
||||
const helloWorld = function() {
|
||||
return 'Hello, World!'
|
|
@ -0,0 +1,7 @@
|
|||
const helloWorld = require('./helloWorld');
|
||||
|
||||
describe('Hello World', function() {
|
||||
test('says "Hello, World!"', function() {
|
||||
expect(helloWorld()).toEqual('Hello, World!');
|
||||
});
|
||||
});
|
|
@ -0,0 +1,5 @@
|
|||
const helloWorld = function () {
|
||||
return "Hello, World!";
|
||||
};
|
||||
|
||||
module.exports = helloWorld;
|
|
@ -0,0 +1,7 @@
|
|||
const helloWorld = require('./helloWorld-solution');
|
||||
|
||||
describe('Hello World', function () {
|
||||
test('says "Hello, World!"', function () {
|
||||
expect(helloWorld()).toEqual('Hello, World!');
|
||||
});
|
||||
});
|
|
@ -6,20 +6,24 @@ Write a function that simply repeats the string a given number of times:
|
|||
repeatString('hey', 3) // returns 'heyheyhey'
|
||||
```
|
||||
|
||||
This function will take two arguments, `string` and `num`.
|
||||
|
||||
*Note:* The exercises after this one will not have arguments provided as this one does - you will need to provide them yourself from now on. So read each exercise's README carefully to see what kinds of arguments will be expected.
|
||||
|
||||
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.
|
||||
|
||||
|
||||
## Hints
|
||||
|
||||
- Take note of the above function call- how exactly is it being called?
|
||||
|
||||
- You're going to want to use a loop for this one.
|
||||
|
||||
- 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 `npm test repeatString.spec.js` returns results similar to the below, make sure you have enabled the rest of the tests, as described in the instructions 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).
|
|
@ -2,4 +2,5 @@ const repeatString = function() {
|
|||
|
||||
};
|
||||
|
||||
// Do not edit below this line
|
||||
module.exports = repeatString;
|
|
@ -28,7 +28,7 @@ describe('repeatString', () => {
|
|||
const number = Math.floor(Math.random() * 1000)
|
||||
/*The .match(/((hey))/g).length is a regex that will count the number of heys
|
||||
in the result, which if your function works correctly will equal the number that
|
||||
was randomaly generated. */
|
||||
was randomly generated. */
|
||||
expect(repeatString('hey', number).match(/((hey))/g).length).toEqual(number);
|
||||
});
|
||||
test.skip('works with blank strings', () => {
|
|
@ -0,0 +1,10 @@
|
|||
const repeatString = function (word, times) {
|
||||
if (times < 0) return "ERROR";
|
||||
let string = "";
|
||||
for (let i = 0; i < times; i++) {
|
||||
string += word;
|
||||
}
|
||||
return string;
|
||||
};
|
||||
|
||||
module.exports = repeatString;
|
|
@ -0,0 +1,39 @@
|
|||
const repeatString = require('./repeatString-solution');
|
||||
|
||||
describe('repeatString', () => {
|
||||
test('repeats the string', () => {
|
||||
expect(repeatString('hey', 3)).toEqual('heyheyhey');
|
||||
});
|
||||
test('repeats the string many times', () => {
|
||||
expect(repeatString('hey', 10)).toEqual('heyheyheyheyheyheyheyheyheyhey');
|
||||
});
|
||||
test('repeats the string 1 times', () => {
|
||||
expect(repeatString('hey', 1)).toEqual('hey');
|
||||
});
|
||||
test('repeats the string 0 times', () => {
|
||||
expect(repeatString('hey', 0)).toEqual('');
|
||||
});
|
||||
test('returns ERROR with negative numbers', () => {
|
||||
expect(repeatString('hey', -1)).toEqual('ERROR');
|
||||
});
|
||||
test('repeats the string a random amount of times', function () {
|
||||
/*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
|
||||
equals a number between 0 to 999 (this number will change everytime you run
|
||||
the test).*/
|
||||
|
||||
// DO NOT use Math.floor(Math.random() * 1000) in your code,
|
||||
// this test generates a random number, then passes it into your code with a function parameter.
|
||||
// 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
|
||||
const number = Math.floor(Math.random() * 1000);
|
||||
/*The .match(/((hey))/g).length is a regex that will count the number of heys
|
||||
in the result, which if your function works correctly will equal the number that
|
||||
was randomaly generated. */
|
||||
expect(repeatString('hey', number).match(/((hey))/g).length).toEqual(
|
||||
number
|
||||
);
|
||||
});
|
||||
test('works with blank strings', () => {
|
||||
expect(repeatString('', 10)).toEqual('');
|
||||
});
|
||||
});
|
|
@ -6,7 +6,8 @@ Pretty simple, write a function called `reverseString` that returns its input, r
|
|||
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 (in the file `reverseString.spec.js`). Currently, only the first test is enabled. After ensuring that the first test passes, enable the remaining tests one by one by removing the `.skip` from the `test.skip()` function.
|
||||
|
||||
|
||||
## 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.
|
|
@ -2,4 +2,5 @@ const reverseString = function() {
|
|||
|
||||
};
|
||||
|
||||
// Do not edit below this line
|
||||
module.exports = reverseString;
|
|
@ -0,0 +1,5 @@
|
|||
const reverseString = function (string) {
|
||||
return string.split("").reverse().join("");
|
||||
};
|
||||
|
||||
module.exports = reverseString;
|
|
@ -0,0 +1,18 @@
|
|||
const reverseString = require('./reverseString-solution');
|
||||
|
||||
describe('reverseString', () => {
|
||||
test('reverses single word', () => {
|
||||
expect(reverseString('hello')).toEqual('olleh');
|
||||
});
|
||||
|
||||
test('reverses multiple words', () => {
|
||||
expect(reverseString('hello there')).toEqual('ereht olleh');
|
||||
});
|
||||
|
||||
test('works with numbers and punctuation', () => {
|
||||
expect(reverseString('123! abc!')).toEqual('!cba !321');
|
||||
});
|
||||
test('works with blank strings', () => {
|
||||
expect(reverseString('')).toEqual('');
|
||||
});
|
||||
});
|
|
@ -2,4 +2,5 @@ const removeFromArray = function() {
|
|||
|
||||
};
|
||||
|
||||
// Do not edit below this line
|
||||
module.exports = removeFromArray;
|
|
@ -0,0 +1,28 @@
|
|||
// we have 2 solutions here, an easier one and a more advanced one.
|
||||
// The easiest way to get an array of the rest of the arguments that are passed to a function
|
||||
// is using the rest operator. If this is unfamiliar to you look it up!
|
||||
const removeFromArray = function (array, ...args) {
|
||||
// create a new empty array
|
||||
const newArray = [];
|
||||
// use forEach to go through the array
|
||||
array.forEach((item) => {
|
||||
// push every element into the new array
|
||||
// UNLESS it is included in the function arguments
|
||||
// so we create a new array with every item, except those that should be removed
|
||||
if (!args.includes(item)) {
|
||||
newArray.push(item);
|
||||
}
|
||||
});
|
||||
// and return that array
|
||||
return newArray;
|
||||
};
|
||||
|
||||
// A simpler, but more advanced way to do it is to use the 'filter' function,
|
||||
// which basically does what we did with the forEach above.
|
||||
|
||||
// var removeFromArray = function(array, ...args) {
|
||||
// return array.filter(val => !args.includes(val))
|
||||
// }
|
||||
//
|
||||
|
||||
module.exports = removeFromArray;
|
|
@ -0,0 +1,25 @@
|
|||
const removeFromArray = require('./removeFromArray-solution');
|
||||
|
||||
describe('removeFromArray', () => {
|
||||
test('removes a single value', () => {
|
||||
expect(removeFromArray([1, 2, 3, 4], 3)).toEqual([1, 2, 4]);
|
||||
});
|
||||
test('removes multiple values', () => {
|
||||
expect(removeFromArray([1, 2, 3, 4], 3, 2)).toEqual([1, 4]);
|
||||
});
|
||||
test('ignores non present values', () => {
|
||||
expect(removeFromArray([1, 2, 3, 4], 7, 'tacos')).toEqual([1, 2, 3, 4]);
|
||||
});
|
||||
test('ignores non present values, but still works', () => {
|
||||
expect(removeFromArray([1, 2, 3, 4], 7, 2)).toEqual([1, 3, 4]);
|
||||
});
|
||||
test('can remove all values', () => {
|
||||
expect(removeFromArray([1, 2, 3, 4], 1, 2, 3, 4)).toEqual([]);
|
||||
});
|
||||
test('works with strings', () => {
|
||||
expect(removeFromArray(['hey', 2, 3, 'ho'], 'hey', 3)).toEqual([2, 'ho']);
|
||||
});
|
||||
test('only removes same type', () => {
|
||||
expect(removeFromArray([1, 2, 3], '1', 3)).toEqual([1, 2]);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,21 @@
|
|||
const sumAll = function (min, max) {
|
||||
if (!Number.isInteger(min) || !Number.isInteger(max)) return "ERROR";
|
||||
if (min < 0 || max < 0) return "ERROR";
|
||||
if (min > max) {
|
||||
const temp = min;
|
||||
min = max;
|
||||
max = temp;
|
||||
}
|
||||
|
||||
// An alternative way to swap the values of min and max like above is to use the array destructuring syntax.
|
||||
// Here's an optional article on it: https://www.freecodecamp.org/news/array-destructuring-in-es6-30e398f21d10/
|
||||
// if (min > max) [min, max] = [max, min];
|
||||
|
||||
let sum = 0;
|
||||
for (let i = min; i <= max; i++) {
|
||||
sum += i;
|
||||
}
|
||||
return sum;
|
||||
};
|
||||
|
||||
module.exports = sumAll;
|
|
@ -0,0 +1,25 @@
|
|||
const sumAll = require('./sumAll-solution');
|
||||
|
||||
describe('sumAll', () => {
|
||||
test('sums numbers within the range', () => {
|
||||
expect(sumAll(1, 4)).toEqual(10);
|
||||
});
|
||||
test('works with large numbers', () => {
|
||||
expect(sumAll(1, 4000)).toEqual(8002000);
|
||||
});
|
||||
test('works with larger number first', () => {
|
||||
expect(sumAll(123, 1)).toEqual(7626);
|
||||
});
|
||||
test('returns ERROR with negative numbers', () => {
|
||||
expect(sumAll(-10, 4)).toEqual('ERROR');
|
||||
});
|
||||
test('returns ERROR with non-integer parameters', () => {
|
||||
expect(sumAll(2.5, 4)).toEqual('ERROR');
|
||||
});
|
||||
test('returns ERROR with non-number parameters', () => {
|
||||
expect(sumAll(10, '90')).toEqual('ERROR');
|
||||
});
|
||||
test('returns ERROR with non-number parameters', () => {
|
||||
expect(sumAll(10, [90, 1])).toEqual('ERROR');
|
||||
});
|
||||
});
|
|
@ -2,4 +2,5 @@ const sumAll = function() {
|
|||
|
||||
};
|
||||
|
||||
// Do not edit below this line
|
||||
module.exports = sumAll;
|
|
@ -2,4 +2,5 @@ const leapYears = function() {
|
|||
|
||||
};
|
||||
|
||||
// Do not edit below this line
|
||||
module.exports = leapYears;
|
|
@ -0,0 +1,5 @@
|
|||
const leapYears = function (year) {
|
||||
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
||||
};
|
||||
|
||||
module.exports = leapYears;
|
|
@ -0,0 +1,22 @@
|
|||
const leapYears = require('./leapYears-solution');
|
||||
|
||||
describe('leapYears', () => {
|
||||
test('works with non century years', () => {
|
||||
expect(leapYears(1996)).toBe(true);
|
||||
});
|
||||
test('works with non century years', () => {
|
||||
expect(leapYears(1997)).toBe(false);
|
||||
});
|
||||
test('works with ridiculously futuristic non century years', () => {
|
||||
expect(leapYears(34992)).toBe(true);
|
||||
});
|
||||
test('works with century years', () => {
|
||||
expect(leapYears(1900)).toBe(false);
|
||||
});
|
||||
test('works with century years', () => {
|
||||
expect(leapYears(1600)).toBe(true);
|
||||
});
|
||||
test('works with century years', () => {
|
||||
expect(leapYears(700)).toBe(false);
|
||||
});
|
||||
});
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
Write two functions that convert temperatures from Fahrenheit to Celsius, and vice versa:
|
||||
```
|
||||
ftoc(32) // fahrenheit to celsius, should return 0
|
||||
convertToCelsius(32) // fahrenheit to celsius, should return 0
|
||||
|
||||
ctof(0) // celsius to fahrenheit, should return 32
|
||||
convertToFahrenheit(0) // celsius to fahrenheit, should return 32
|
||||
```
|
||||
|
||||
Because we are human, we want the result temperature to be rounded to one decimal place: i.e., `ftoc(100)` should return `37.8` and not `37.77777777777778`.
|
||||
Because we are human, we want the result temperature to be rounded to one decimal place: i.e., `convertToCelsius(100)` should return `37.8` and not `37.77777777777778`.
|
||||
|
||||
This exercise asks you to create more than one function so the `module.exports` section of the spec file looks a little different this time. Nothing to worry about, we're just packaging both functions into a single object to be exported.
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
const convertToCelsius = function (fahrenheit) {
|
||||
return Math.round((fahrenheit - 32) * (5 / 9) * 10) / 10;
|
||||
};
|
||||
|
||||
const convertToFahrenheit = function (celsius) {
|
||||
return Math.round(((celsius * 9) / 5 + 32) * 10) / 10;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
convertToCelsius,
|
||||
convertToFahrenheit,
|
||||
};
|
|
@ -0,0 +1,28 @@
|
|||
const {
|
||||
convertToCelsius,
|
||||
convertToFahrenheit,
|
||||
} = require('./tempConversion-solution');
|
||||
|
||||
describe('convertToCelsius', () => {
|
||||
test('works', () => {
|
||||
expect(convertToCelsius(32)).toEqual(0);
|
||||
});
|
||||
test('rounds to 1 decimal', () => {
|
||||
expect(convertToCelsius(100)).toEqual(37.8);
|
||||
});
|
||||
test('works with negatives', () => {
|
||||
expect(convertToCelsius(-100)).toEqual(-73.3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('convertToFahrenheit', () => {
|
||||
test('works', () => {
|
||||
expect(convertToFahrenheit(0)).toEqual(32);
|
||||
});
|
||||
test('rounds to 1 decimal', () => {
|
||||
expect(convertToFahrenheit(73.2)).toEqual(163.8);
|
||||
});
|
||||
test('works with negatives', () => {
|
||||
expect(convertToFahrenheit(-10)).toEqual(14);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,11 @@
|
|||
const convertToCelsius = function() {
|
||||
};
|
||||
|
||||
const convertToFahrenheit = function() {
|
||||
};
|
||||
|
||||
// Do not edit below this line
|
||||
module.exports = {
|
||||
convertToCelsius,
|
||||
convertToFahrenheit
|
||||
};
|
|
@ -0,0 +1,25 @@
|
|||
const {convertToCelsius, convertToFahrenheit} = require('./tempConversion')
|
||||
|
||||
describe('convertToCelsius', () => {
|
||||
test('works', () => {
|
||||
expect(convertToCelsius(32)).toEqual(0);
|
||||
});
|
||||
test.skip('rounds to 1 decimal', () => {
|
||||
expect(convertToCelsius(100)).toEqual(37.8);
|
||||
});
|
||||
test.skip('works with negatives', () => {
|
||||
expect(convertToCelsius(-100)).toEqual(-73.3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('convertToFahrenheit', () => {
|
||||
test.skip('works', () => {
|
||||
expect(convertToFahrenheit(0)).toEqual(32);
|
||||
});
|
||||
test.skip('rounds to 1 decimal', () => {
|
||||
expect(convertToFahrenheit(73.2)).toEqual(163.8);
|
||||
});
|
||||
test.skip('works with negatives', () => {
|
||||
expect(convertToFahrenheit(-10)).toEqual(14);
|
||||
});
|
||||
});
|
|
@ -22,6 +22,7 @@ const factorial = function() {
|
|||
|
||||
};
|
||||
|
||||
// Do not edit below this line
|
||||
module.exports = {
|
||||
add,
|
||||
subtract,
|
|
@ -0,0 +1,77 @@
|
|||
const calculator = require('./calculator');
|
||||
|
||||
describe('add', () => {
|
||||
test('adds 0 and 0', () => {
|
||||
expect(calculator.add(0, 0)).toBe(0);
|
||||
});
|
||||
|
||||
test.skip('adds 2 and 2', () => {
|
||||
expect(calculator.add(2, 2)).toBe(4);
|
||||
});
|
||||
|
||||
test.skip('adds positive numbers', () => {
|
||||
expect(calculator.add(2, 6)).toBe(8);
|
||||
});
|
||||
});
|
||||
|
||||
describe('subtract', () => {
|
||||
test.skip('subtracts numbers', () => {
|
||||
expect(calculator.subtract(10, 4)).toBe(6);
|
||||
});
|
||||
});
|
||||
|
||||
describe('sum', () => {
|
||||
test.skip('computes the sum of an empty array', () => {
|
||||
expect(calculator.sum([])).toBe(0);
|
||||
});
|
||||
|
||||
test.skip('computes the sum of an array of one number', () => {
|
||||
expect(calculator.sum([7])).toBe(7);
|
||||
});
|
||||
|
||||
test.skip('computes the sum of an array of two numbers', () => {
|
||||
expect(calculator.sum([7, 11])).toBe(18);
|
||||
});
|
||||
|
||||
test.skip('computes the sum of an array of many numbers', () => {
|
||||
expect(calculator.sum([1, 3, 5, 7, 9])).toBe(25);
|
||||
});
|
||||
});
|
||||
|
||||
describe('multiply', () => {
|
||||
test.skip('multiplies two numbers', () => {
|
||||
expect(calculator.multiply([2, 4])).toBe(8);
|
||||
});
|
||||
|
||||
test.skip('multiplies several numbers', () => {
|
||||
expect(calculator.multiply([2, 4, 6, 8, 10, 12, 14])).toBe(645120);
|
||||
});
|
||||
});
|
||||
|
||||
describe('power', () => {
|
||||
test.skip('raises one number to the power of another number', () => {
|
||||
expect(calculator.power(4, 3)).toBe(64); // 4 to third power is 64
|
||||
});
|
||||
});
|
||||
|
||||
describe('factorial', () => {
|
||||
test.skip('computes the factorial of 0', () => {
|
||||
expect(calculator.factorial(0)).toBe(1); // 0! = 1
|
||||
});
|
||||
|
||||
test.skip('computes the factorial of 1', () => {
|
||||
expect(calculator.factorial(1)).toBe(1);
|
||||
});
|
||||
|
||||
test.skip('computes the factorial of 2', () => {
|
||||
expect(calculator.factorial(2)).toBe(2);
|
||||
});
|
||||
|
||||
test.skip('computes the factorial of 5', () => {
|
||||
expect(calculator.factorial(5)).toBe(120);
|
||||
});
|
||||
|
||||
test.skip('computes the factorial of 10', () => {
|
||||
expect(calculator.factorial(10)).toBe(3628800);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,46 @@
|
|||
const add = function (a, b) {
|
||||
return a + b;
|
||||
};
|
||||
|
||||
const subtract = function (a, b) {
|
||||
return a - b;
|
||||
};
|
||||
|
||||
const sum = function (array) {
|
||||
return array.reduce((total, current) => total + current, 0);
|
||||
};
|
||||
|
||||
const multiply = function (array) {
|
||||
return array.reduce((product, current) => product * current)
|
||||
};
|
||||
|
||||
const power = function (a, b) {
|
||||
return Math.pow(a, b);
|
||||
};
|
||||
|
||||
const factorial = function (n) {
|
||||
if (n === 0) return 1;
|
||||
let product = 1;
|
||||
for (let i = n; i > 0; i--) {
|
||||
product *= i;
|
||||
}
|
||||
return product;
|
||||
};
|
||||
|
||||
// This is another implementation of Factorial that uses recursion
|
||||
// THANKS to @ThirtyThreeB!
|
||||
const recursiveFactorial = function (n) {
|
||||
if (n === 0) {
|
||||
return 1;
|
||||
}
|
||||
return n * recursiveFactorial(n - 1);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
add,
|
||||
subtract,
|
||||
sum,
|
||||
multiply,
|
||||
power,
|
||||
factorial,
|
||||
};
|
|
@ -0,0 +1,77 @@
|
|||
const calculator = require('./calculator-solution');
|
||||
|
||||
describe('add', () => {
|
||||
test('adds 0 and 0', () => {
|
||||
expect(calculator.add(0, 0)).toBe(0);
|
||||
});
|
||||
|
||||
test('adds 2 and 2', () => {
|
||||
expect(calculator.add(2, 2)).toBe(4);
|
||||
});
|
||||
|
||||
test('adds positive numbers', () => {
|
||||
expect(calculator.add(2, 6)).toBe(8);
|
||||
});
|
||||
});
|
||||
|
||||
describe('subtract', () => {
|
||||
test('subtracts numbers', () => {
|
||||
expect(calculator.subtract(10, 4)).toBe(6);
|
||||
});
|
||||
});
|
||||
|
||||
describe('sum', () => {
|
||||
test('computes the sum of an empty array', () => {
|
||||
expect(calculator.sum([])).toBe(0);
|
||||
});
|
||||
|
||||
test('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', () => {
|
||||
expect(calculator.sum([7, 11])).toBe(18);
|
||||
});
|
||||
|
||||
test('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', () => {
|
||||
expect(calculator.multiply([2, 4])).toBe(8);
|
||||
});
|
||||
|
||||
test('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', () => {
|
||||
expect(calculator.power(4, 3)).toBe(64); // 4 to third power is 64
|
||||
});
|
||||
});
|
||||
|
||||
describe('factorial', () => {
|
||||
test('computes the factorial of 0', () => {
|
||||
expect(calculator.factorial(0)).toBe(1); // 0! = 1
|
||||
});
|
||||
|
||||
test('computes the factorial of 1', () => {
|
||||
expect(calculator.factorial(1)).toBe(1);
|
||||
});
|
||||
|
||||
test('computes the factorial of 2', () => {
|
||||
expect(calculator.factorial(2)).toBe(2);
|
||||
});
|
||||
|
||||
test('computes the factorial of 5', () => {
|
||||
expect(calculator.factorial(5)).toBe(120);
|
||||
});
|
||||
|
||||
test('computes the factorial of 10', () => {
|
||||
expect(calculator.factorial(10)).toBe(3628800);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,6 @@
|
|||
const palindromes = function () {
|
||||
|
||||
};
|
||||
|
||||
// Do not edit below this line
|
||||
module.exports = palindromes;
|
|
@ -17,6 +17,12 @@ describe('palindromes', () => {
|
|||
expect(palindromes('Animal loots foliated detail of stool lamina.')).toBe(true);
|
||||
});
|
||||
test.skip('doesn\'t just always return true', () => {
|
||||
expect(palindromes('ZZZZ car, a man, a maraca.')).toBe(false);
|
||||
expect(palindromes('ZZZZ car, a man, a maracaz.')).toBe(false);
|
||||
});
|
||||
test.skip('works with numbers in a string', () => {
|
||||
expect(palindromes('rac3e3car')).toBe(true);
|
||||
});
|
||||
test.skip('works with unevenly spaced numbers in a string', () => {
|
||||
expect(palindromes('r3ace3car')).toBe(false);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,6 @@
|
|||
const palindromes = function (string) {
|
||||
const processedString = string.toLowerCase().replace(/[^a-z0-9]/g, "");
|
||||
return processedString.split("").reverse().join("") == processedString;
|
||||
};
|
||||
|
||||
module.exports = palindromes;
|
|
@ -0,0 +1,30 @@
|
|||
const palindromes = require('./palindromes-solution');
|
||||
|
||||
describe('palindromes', () => {
|
||||
test('works with single words', () => {
|
||||
expect(palindromes('racecar')).toBe(true);
|
||||
});
|
||||
test('works with punctuation ', () => {
|
||||
expect(palindromes('racecar!')).toBe(true);
|
||||
});
|
||||
test('works with upper-case letters ', () => {
|
||||
expect(palindromes('Racecar!')).toBe(true);
|
||||
});
|
||||
test('works with multiple words', () => {
|
||||
expect(palindromes('A car, a man, a maraca.')).toBe(true);
|
||||
});
|
||||
test('works with multiple words', () => {
|
||||
expect(palindromes('Animal loots foliated detail of stool lamina.')).toBe(
|
||||
true
|
||||
);
|
||||
});
|
||||
test("doesn't just always return true", () => {
|
||||
expect(palindromes('ZZZZ car, a man, a maraca.')).toBe(false);
|
||||
});
|
||||
test('works with numbers in a string', () => {
|
||||
expect(palindromes('rac3e3car')).toBe(true);
|
||||
});
|
||||
test('works with unevenly spaced numbers in a string', () => {
|
||||
expect(palindromes('r3ace3car')).toBe(false);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,12 @@
|
|||
# Exercise 10 - Fibonacci
|
||||
|
||||
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.
|
||||
> In this exercise, the Fibonacci sequence used is 1, 1, 2, 3, 5, 8, etc.
|
||||
> To learn more about Fibonacci sequences, go to: https://en.wikipedia.org/wiki/Fibonacci_sequence
|
||||
|
||||
```javascript
|
||||
fibonacci(4); // returns the 4th member of the series: 3 (1, 1, 2, 3)
|
||||
fibonacci(6); // returns 8
|
||||
```
|
|
@ -2,4 +2,5 @@ const fibonacci = function() {
|
|||
|
||||
};
|
||||
|
||||
// Do not edit below this line
|
||||
module.exports = fibonacci;
|
|
@ -16,9 +16,15 @@ describe('fibonacci', () => {
|
|||
test.skip('25th fibonacci number is 75025', () => {
|
||||
expect(fibonacci(25)).toBe(75025);
|
||||
});
|
||||
test.skip('0th fibonacci number is 0', () => {
|
||||
expect(fibonacci(0)).toBe(0);
|
||||
});
|
||||
test.skip('doesn\'t accept negatives', () => {
|
||||
expect(fibonacci(-25)).toBe("OOPS");
|
||||
});
|
||||
test.skip('DOES accept strings', () => {
|
||||
expect(fibonacci("0")).toBe(0);
|
||||
});
|
||||
test.skip('DOES accept strings', () => {
|
||||
expect(fibonacci("1")).toBe(1);
|
||||
});
|
|
@ -0,0 +1,34 @@
|
|||
const fibonacci = function(countArg) {
|
||||
// checks argument's type and makes sure we use
|
||||
// a number throughout rest of function.
|
||||
let count
|
||||
if (typeof countArg !== 'number') {
|
||||
count = parseInt(countArg)
|
||||
} else {
|
||||
count = countArg
|
||||
}
|
||||
|
||||
if (count < 0) return "OOPS";
|
||||
if (count == 0) return 0;
|
||||
|
||||
let firstPrev = 1;
|
||||
let secondPrev = 0;
|
||||
|
||||
for (let i = 2; i <= count; i++) {
|
||||
let current = firstPrev + secondPrev;
|
||||
secondPrev = firstPrev;
|
||||
firstPrev = current;
|
||||
}
|
||||
|
||||
return firstPrev;
|
||||
|
||||
};
|
||||
|
||||
// Another way to do it is by using an iterative approach with an array containing two values, 0 and 1.
|
||||
// const fib = [0, 1];
|
||||
// for (let i = 2; i <= count; i++) {
|
||||
// fib[i] = fib[i - 1] + fib[i - 2];
|
||||
// }
|
||||
// return fib[count];
|
||||
|
||||
module.exports = fibonacci;
|
|
@ -0,0 +1,37 @@
|
|||
const fibonacci = require('./fibonacci-solution')
|
||||
|
||||
describe('fibonacci', () => {
|
||||
test('4th fibonacci number is 3', () => {
|
||||
expect(fibonacci(4)).toBe(3);
|
||||
});
|
||||
test('6th fibonacci number is 8', () => {
|
||||
expect(fibonacci(6)).toBe(8);
|
||||
});
|
||||
test('10th fibonacci number is 55', () => {
|
||||
expect(fibonacci(10)).toBe(55);
|
||||
});
|
||||
test('15th fibonacci number is 610', () => {
|
||||
expect(fibonacci(15)).toBe(610);
|
||||
});
|
||||
test('25th fibonacci number is 75025', () => {
|
||||
expect(fibonacci(25)).toBe(75025);
|
||||
});
|
||||
test('0th fibonacci number is 0', () => {
|
||||
expect(fibonacci(0)).toBe(0);
|
||||
});
|
||||
test('doesn\'t accept negatives', () => {
|
||||
expect(fibonacci(-25)).toBe("OOPS");
|
||||
});
|
||||
test('DOES accept strings', () => {
|
||||
expect(fibonacci("0")).toBe(0);
|
||||
});
|
||||
test('DOES accept strings', () => {
|
||||
expect(fibonacci("1")).toBe(1);
|
||||
});
|
||||
test('DOES accept strings', () => {
|
||||
expect(fibonacci("2")).toBe(1);
|
||||
});
|
||||
test('DOES accept strings', () => {
|
||||
expect(fibonacci("8")).toBe(21);
|
||||
});
|
||||
});
|
|
@ -2,4 +2,5 @@ const getTheTitles = function() {
|
|||
|
||||
};
|
||||
|
||||
// Do not edit below this line
|
||||
module.exports = getTheTitles;
|
|
@ -0,0 +1,5 @@
|
|||
const getTheTitles = function (array) {
|
||||
return array.map((book) => book.title);
|
||||
};
|
||||
|
||||
module.exports = getTheTitles;
|
|
@ -0,0 +1,18 @@
|
|||
const getTheTitles = require('./getTheTitles-solution');
|
||||
|
||||
describe('getTheTitles', () => {
|
||||
const books = [
|
||||
{
|
||||
title: 'Book',
|
||||
author: 'Name',
|
||||
},
|
||||
{
|
||||
title: 'Book2',
|
||||
author: 'Name2',
|
||||
},
|
||||
];
|
||||
|
||||
test('gets titles', () => {
|
||||
expect(getTheTitles(books)).toEqual(['Book', 'Book2']);
|
||||
});
|
||||
});
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
Given an array of objects representing people with a birth and death year, return the oldest person.
|
||||
|
||||
Now that you've reached the final exercise, you should be fairly comfortable getting the information you need from test case(s). Take a look at how the array of objects is constructed in this exercise's test cases to help you write your function.
|
||||
|
||||
## 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`.
|
||||
- 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.
|
|
@ -2,4 +2,5 @@ const findTheOldest = function() {
|
|||
|
||||
};
|
||||
|
||||
// Do not edit below this line
|
||||
module.exports = findTheOldest;
|
|
@ -1,7 +1,7 @@
|
|||
const findTheOldest = require('./findTheOldest')
|
||||
|
||||
describe('findTheOldest', () => {
|
||||
test('finds the oldest person!', () => {
|
||||
test('finds the person with the greatest age!', () => {
|
||||
const people = [
|
||||
{
|
||||
name: "Carly",
|
||||
|
@ -21,7 +21,7 @@ describe('findTheOldest', () => {
|
|||
]
|
||||
expect(findTheOldest(people).name).toBe('Ray');
|
||||
});
|
||||
test.skip('finds the oldest person if someone is still living', () => {
|
||||
test.skip('finds the person with the greatest age if someone is still living', () => {
|
||||
const people = [
|
||||
{
|
||||
name: "Carly",
|
||||
|
@ -40,7 +40,7 @@ describe('findTheOldest', () => {
|
|||
]
|
||||
expect(findTheOldest(people).name).toBe('Ray');
|
||||
});
|
||||
test.skip('finds the oldest person if the OLDEST is still living', () => {
|
||||
test.skip('finds the person with the greatest age if the OLDEST is still living', () => {
|
||||
const people = [
|
||||
{
|
||||
name: "Carly",
|
|
@ -0,0 +1,19 @@
|
|||
const findTheOldest = function (array) {
|
||||
return array.reduce((oldest, currentPerson) => {
|
||||
const oldestAge = getAge(oldest.yearOfBirth, oldest.yearOfDeath);
|
||||
const currentAge = getAge(
|
||||
currentPerson.yearOfBirth,
|
||||
currentPerson.yearOfDeath
|
||||
);
|
||||
return oldestAge < currentAge ? currentPerson : oldest;
|
||||
});
|
||||
};
|
||||
|
||||
const getAge = function (birth, death) {
|
||||
if (!death) {
|
||||
death = new Date().getFullYear();
|
||||
}
|
||||
return death - birth;
|
||||
};
|
||||
|
||||
module.exports = findTheOldest;
|
|
@ -0,0 +1,62 @@
|
|||
const findTheOldest = require('./findTheOldest-solution');
|
||||
|
||||
describe('findTheOldest', () => {
|
||||
test('finds the oldest person!', () => {
|
||||
const people = [
|
||||
{
|
||||
name: 'Carly',
|
||||
yearOfBirth: 1942,
|
||||
yearOfDeath: 1970,
|
||||
},
|
||||
{
|
||||
name: 'Ray',
|
||||
yearOfBirth: 1962,
|
||||
yearOfDeath: 2011,
|
||||
},
|
||||
{
|
||||
name: 'Jane',
|
||||
yearOfBirth: 1912,
|
||||
yearOfDeath: 1941,
|
||||
},
|
||||
];
|
||||
expect(findTheOldest(people).name).toBe('Ray');
|
||||
});
|
||||
test('finds the oldest person if someone is still living', () => {
|
||||
const people = [
|
||||
{
|
||||
name: 'Carly',
|
||||
yearOfBirth: 2018,
|
||||
},
|
||||
{
|
||||
name: 'Ray',
|
||||
yearOfBirth: 1962,
|
||||
yearOfDeath: 2011,
|
||||
},
|
||||
{
|
||||
name: 'Jane',
|
||||
yearOfBirth: 1912,
|
||||
yearOfDeath: 1941,
|
||||
},
|
||||
];
|
||||
expect(findTheOldest(people).name).toBe('Ray');
|
||||
});
|
||||
test('finds the oldest person if the OLDEST is still living', () => {
|
||||
const people = [
|
||||
{
|
||||
name: 'Carly',
|
||||
yearOfBirth: 1066,
|
||||
},
|
||||
{
|
||||
name: 'Ray',
|
||||
yearOfBirth: 1962,
|
||||
yearOfDeath: 2011,
|
||||
},
|
||||
{
|
||||
name: 'Jane',
|
||||
yearOfBirth: 1912,
|
||||
yearOfDeath: 1941,
|
||||
},
|
||||
];
|
||||
expect(findTheOldest(people).name).toBe('Carly');
|
||||
});
|
||||
});
|
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2023 The Odin Project
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
43
README.md
43
README.md
|
@ -1,27 +1,38 @@
|
|||
These are a series of JavaScript exercises intended to be used alongside the curriculum at 'The Odin Project'. They start simple and easy but get more complex and involved as you progress through them.
|
||||
# JavaScript Exercises
|
||||
|
||||
There will eventually be a suggested order of completion, but at this time since we are still in the process of creating more exercises the order is subject to change and has not yet been specified. However, there are a few exercises that make a good "starting point". Feel free to at least start with these:
|
||||
These JavaScript exercises are intended to complement the JavaScript content on The Odin Project (TOP). They should only be done when instructed during the course of the curriculum.
|
||||
|
||||
1. Hello World
|
||||
2. Repeat String
|
||||
3. Reverse String
|
||||
**Note:** The `generator-exercise` file is not actually an exercise; it is a script that generates exercises. It was created to help efficiently write these exercises.
|
||||
|
||||
## Contributing
|
||||
|
||||
If you have a suggestion to improve an exercise, an idea for a new exercise, or notice an issue with an exercise, please feel free to open an issue after thoroughly reading our [contributing guide](https://github.com/TheOdinProject/.github/blob/main/CONTRIBUTING.md).
|
||||
|
||||
## How To Use These Exercises
|
||||
Before you start you should have a few things installed on your machine:
|
||||
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).
|
||||
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.
|
||||
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).
|
||||
|
||||
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.
|
||||
|
||||
1. Fork and clone this repository. To learn how to fork a repository, see the GitHub documentation on how to [fork a repo](https://docs.github.com/en/get-started/quickstart/fork-a-repo).
|
||||
- Copies of repositories on your machine are called clones. If you need help cloning to your local environment you can learn how from the GitHub documentation on [cloning a repository](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository-from-github/cloning-a-repository).
|
||||
2. Before you start working on any exercises, you should first ensure you have the following installed:
|
||||
- **NPM**. You should have installed NPM already in our [Installing Node.js](https://www.theodinproject.com/paths/foundations/courses/foundations/lessons/installing-node-js) lesson. Just in case you need to check, 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` as this causes permission issues. Instead, go back to the installation lesson and install Node with NVM by following the instructions there.
|
||||
- **Jest**. After cloning this repository to your local machine and installing NPM, go into the newly created directory (`cd javascript-exercises`) and run `npm install`. This will install Jest and set up the testing platform based on our preconfigured settings. (Note: if you get warnings that packages are out of date or contain vulnerabilities, you can safely ignore them for these exercises.)
|
||||
|
||||
3. Each exercise includes the following:
|
||||
|
||||
- A markdown file with a description of the task, an empty (or mostly empty) JavaScript file, and a set of tests.
|
||||
- A `solutions` directory that contains a solution and the same test file with all of the tests unskipped.
|
||||
|
||||
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.
|
||||
4. Some of the exercises have test conditions defined in their spec file as `test.skip` compared to `test`. This is purposeful. After you pass one `test`, you will change the next `test.skip` to `test` and test your code again. You'll do this until all conditions are satisfied. **All tests must pass at the same time**, and you should not have any `test.skip` instances by the time you finish an exercise.
|
||||
5. Once you successfully finish an exercise, check the `solutions` directory within each exercise to compare it with yours.
|
||||
- You should not be checking the solution for an exercise until you finish it!
|
||||
- Keep in mind that TOP's solution is not the only solution. Generally as long as all of the tests pass, your solution should be fine.
|
||||
6. Do not submit your solutions to this repo, as any PRs that do so will be closed without merging.
|
||||
|
||||
**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.
|
||||
|
||||
## Solutions
|
||||
## Debugging
|
||||
|
||||
Solutions for these exercises can be found in this repo on the 'solutions' branch.
|
||||
|
||||
## A quick note!
|
||||
|
||||
The exercise `generator-exercise` is not actually an exercise; it is a script that generates exercises. It was created to help efficiently write these exercises.
|
||||
To debug functions, you can run the tests in the Visual Studio Code debugger terminal. You can open this by clicking the "Run and Debug" icon on the left or pressing <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>D</kbd>, then clicking JavaScript Debug Terminal. You will be able to set breakpoints as you would in the Chrome DevTools debugger. You can run `npm test exerciseName.spec.js` to then execute your code up until your breakpoint and step through your code as necessary. **NOTE**: To take advantage of the debugger, you **MUST** run the script in the debugger terminal, not the bash or zsh terminal.
|
||||
|
|
|
@ -14,7 +14,7 @@ caesar('A', 1) // simply shifts the letter by 1: returns 'B'
|
|||
|
||||
the cipher should retain capitalization:
|
||||
```javascript
|
||||
caesar('Hey', 5) // returns 'Mjd;
|
||||
caesar('Hey', 5) // returns 'Mjd'
|
||||
```
|
||||
|
||||
should _not_ shift punctuation:
|
|
@ -2,4 +2,5 @@ const caesar = function() {
|
|||
|
||||
};
|
||||
|
||||
// Do not edit below this line
|
||||
module.exports = caesar;
|
|
@ -0,0 +1,26 @@
|
|||
const caesar = function (string, shift) {
|
||||
return string
|
||||
.split("")
|
||||
.map((char) => shiftChar(char, shift))
|
||||
.join("");
|
||||
};
|
||||
|
||||
const codeSet = (code) => (code < 97 ? 65 : 97);
|
||||
|
||||
// this function is just a fancy way of doing % so that it works with negative numbers
|
||||
// see this link for details:
|
||||
// https://stackoverflow.com/questions/4467539/javascript-modulo-gives-a-negative-result-for-negative-numbers
|
||||
const mod = (n, m) => ((n % m) + m) % m;
|
||||
|
||||
const shiftChar = (char, shift) => {
|
||||
const code = char.charCodeAt();
|
||||
|
||||
if ((code >= 65 && code <= 90) || (code >= 97 && code <= 122)) {
|
||||
return String.fromCharCode(
|
||||
mod(code + shift - codeSet(code), 26) + codeSet(code)
|
||||
);
|
||||
}
|
||||
return char;
|
||||
};
|
||||
|
||||
module.exports = caesar;
|
|
@ -0,0 +1,23 @@
|
|||
const caesar = require('./caesar-solution');
|
||||
|
||||
test('works with single letters', () => {
|
||||
expect(caesar('A', 1)).toBe('B');
|
||||
});
|
||||
test('works with words', () => {
|
||||
expect(caesar('Aaa', 1)).toBe('Bbb');
|
||||
});
|
||||
test('works with phrases', () => {
|
||||
expect(caesar('Hello, World!', 5)).toBe('Mjqqt, Btwqi!');
|
||||
});
|
||||
test('works with negative shift', () => {
|
||||
expect(caesar('Mjqqt, Btwqi!', -5)).toBe('Hello, World!');
|
||||
});
|
||||
test('wraps', () => {
|
||||
expect(caesar('Z', 1)).toBe('A');
|
||||
});
|
||||
test('works with large shift factors', () => {
|
||||
expect(caesar('Hello, World!', 75)).toBe('Ebiil, Tloia!');
|
||||
});
|
||||
test('works with large negative shift factors', () => {
|
||||
expect(caesar('Hello, World!', -29)).toBe('Ebiil, Tloia!');
|
||||
});
|
|
@ -0,0 +1,6 @@
|
|||
function pigLatin(string) {
|
||||
|
||||
};
|
||||
|
||||
// Do not edit below this line
|
||||
module.exports = pigLatin;
|
|
@ -0,0 +1,21 @@
|
|||
const pigLatin = function (string) {
|
||||
return string
|
||||
.split(" ")
|
||||
.map((word) => {
|
||||
const index = firstVowelIndex(word);
|
||||
const beginning = word.slice(0, index);
|
||||
const ending = word.slice(index);
|
||||
return `${ending}${beginning}ay`;
|
||||
})
|
||||
.join(" ");
|
||||
};
|
||||
|
||||
const firstVowelIndex = function (string) {
|
||||
const vowels = string.match(/[aeiou]/g);
|
||||
if (vowels[0] == "u" && string[string.indexOf(vowels[0]) - 1] == "q") {
|
||||
return string.indexOf(vowels[1]);
|
||||
}
|
||||
return string.indexOf(vowels[0]);
|
||||
};
|
||||
|
||||
module.exports = pigLatin;
|
|
@ -0,0 +1,56 @@
|
|||
const pigLatin = require('./pigLatin-solution');
|
||||
|
||||
// Topics
|
||||
|
||||
// * modules
|
||||
// * strings
|
||||
|
||||
// Pig Latin
|
||||
|
||||
// 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.
|
||||
|
||||
// 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 test 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('translates a word beginning with a consonant', () => {
|
||||
expect(pigLatin('banana')).toBe('ananabay');
|
||||
});
|
||||
|
||||
test('translates a word beginning with two consonants', () => {
|
||||
expect(pigLatin('cherry')).toBe('errychay');
|
||||
});
|
||||
|
||||
test('translates two words', () => {
|
||||
expect(pigLatin('eat pie')).toBe('eatay iepay');
|
||||
});
|
||||
|
||||
test('translates a word beginning with three consonants', () => {
|
||||
expect(pigLatin('three')).toBe('eethray');
|
||||
});
|
||||
|
||||
test('counts "sch" as a single phoneme', () => {
|
||||
expect(pigLatin('school')).toBe('oolschay');
|
||||
});
|
||||
|
||||
test('counts "qu" as a single phoneme', () => {
|
||||
expect(pigLatin('quiet')).toBe('ietquay');
|
||||
});
|
||||
|
||||
test('counts "qu" as a consonant even when its preceded by a consonant', () => {
|
||||
expect(pigLatin('square')).toBe('aresquay');
|
||||
});
|
||||
|
||||
test('translates many words', () => {
|
||||
expect(pigLatin('the quick brown fox')).toBe('ethay ickquay ownbray oxfay');
|
||||
});
|
||||
});
|
|
@ -2,4 +2,5 @@ const snakeCase = function() {
|
|||
|
||||
};
|
||||
|
||||
// Do not edit below this line
|
||||
module.exports = snakeCase;
|
|
@ -0,0 +1,19 @@
|
|||
const snakeCase = function (string) {
|
||||
// wtf case
|
||||
string = string.replace(/\.\./g, " ");
|
||||
|
||||
// this splits up camelcase IF there are no spaces in the word
|
||||
if (string.indexOf(" ") < 0) {
|
||||
string = string.replace(/([A-Z])/g, " $1");
|
||||
}
|
||||
|
||||
return string
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
.replace(/[,\?\.]/g, "")
|
||||
.replace(/\-/g, " ")
|
||||
.split(" ")
|
||||
.join("_");
|
||||
};
|
||||
|
||||
module.exports = snakeCase;
|
|
@ -0,0 +1,26 @@
|
|||
const snakeCase = require('./snakeCase-solution');
|
||||
|
||||
describe('snakeCase', () => {
|
||||
test('works with simple lowercased phrases', () => {
|
||||
expect(snakeCase('hello world')).toEqual('hello_world');
|
||||
});
|
||||
test('works with Caps and punctuation', () => {
|
||||
expect(snakeCase('Hello, World???')).toEqual('hello_world');
|
||||
});
|
||||
test('works with longer phrases', () => {
|
||||
expect(snakeCase('This is the song that never ends....')).toEqual(
|
||||
'this_is_the_song_that_never_ends'
|
||||
);
|
||||
});
|
||||
test('works with camel case', () => {
|
||||
expect(snakeCase('snakeCase')).toEqual('snake_case');
|
||||
});
|
||||
test('works with kebab case', () => {
|
||||
expect(snakeCase('snake-case')).toEqual('snake_case');
|
||||
});
|
||||
test('works with WTF case', () => {
|
||||
expect(snakeCase('SnAkE..CaSe..Is..AwEsOmE')).toEqual(
|
||||
'snake_case_is_awesome'
|
||||
);
|
||||
});
|
||||
});
|
Binary file not shown.
|
@ -1,77 +0,0 @@
|
|||
const calculator = require('./calculator');
|
||||
|
||||
describe('add', () => {
|
||||
test('adds 0 and 0', () => {
|
||||
expect(calculator.add(0,0)).toBe(0);
|
||||
});
|
||||
|
||||
test.skip('adds 2 and 2', () => {
|
||||
expect(calculator.add(2,2)).toBe(4);
|
||||
});
|
||||
|
||||
test.skip('adds positive numbers', () => {
|
||||
expect(calculator.add(2,6)).toBe(8);
|
||||
});
|
||||
});
|
||||
|
||||
describe('subtract', () => {
|
||||
test.skip('subtracts numbers', () => {
|
||||
expect(calculator.subtract(10,4)).toBe(6);
|
||||
});
|
||||
});
|
||||
|
||||
describe('sum', () => {
|
||||
test.skip('computes the sum of an empty array', () => {
|
||||
expect(calculator.sum([])).toBe(0);
|
||||
});
|
||||
|
||||
test.skip('computes the sum of an array of one number', () => {
|
||||
expect(calculator.sum([7])).toBe(7);
|
||||
});
|
||||
|
||||
test.skip('computes the sum of an array of two numbers', () => {
|
||||
expect(calculator.sum([7,11])).toBe(18);
|
||||
});
|
||||
|
||||
test.skip('computes the sum of an array of many numbers', () => {
|
||||
expect(calculator.sum([1,3,5,7,9])).toBe(25);
|
||||
});
|
||||
});
|
||||
|
||||
describe('multiply', () => {
|
||||
test.skip('multiplies two numbers', () => {
|
||||
expect(calculator.multiply([2,4])).toBe(8);
|
||||
});
|
||||
|
||||
test.skip('multiplies several numbers', () => {
|
||||
expect(calculator.multiply([2,4,6,8,10,12,14])).toBe(645120);
|
||||
});
|
||||
});
|
||||
|
||||
describe('power', () => {
|
||||
test.skip('raises one number to the power of another number', () => {
|
||||
expect(calculator.power(4,3)).toBe(64); // 4 to third power is 64
|
||||
});
|
||||
});
|
||||
|
||||
describe('factorial', () => {
|
||||
test.skip('computes the factorial of 0', () => {
|
||||
expect(calculator.factorial(0)).toBe(1); // 0! = 1
|
||||
});
|
||||
|
||||
test.skip('computes the factorial of 1', () => {
|
||||
expect(calculator.factorial(1)).toBe(1);
|
||||
});
|
||||
|
||||
test.skip('computes the factorial of 2', () => {
|
||||
expect(calculator.factorial(2)).toBe(2);
|
||||
});
|
||||
|
||||
test.skip('computes the factorial of 5', () => {
|
||||
expect(calculator.factorial(5)).toBe(120);
|
||||
});
|
||||
|
||||
test.skip('computes the factorial of 10', () => {
|
||||
expect(calculator.factorial(10)).toBe(3628800);
|
||||
});
|
||||
});
|
|
@ -1,10 +0,0 @@
|
|||
# Exercise 10 - Fibonacci
|
||||
|
||||
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.
|
||||
|
||||
```javascript
|
||||
fibonacci(4) // returns the 4th member of the series: 3 (1, 1, 2, 3)
|
||||
fibonacci(6) // returns 8
|
||||
```
|
File diff suppressed because it is too large
Load Diff
|
@ -19,7 +19,7 @@
|
|||
"devDependencies": {
|
||||
"yeoman-test": "^1.6.0",
|
||||
"yeoman-assert": "^3.0.0",
|
||||
"nsp": "^2.6.3",
|
||||
"nsp": "^3.2.1",
|
||||
"eslint": "^4.1.0",
|
||||
"eslint-config-xo-space": "^0.16.0",
|
||||
"jest": "^19.0.2",
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
const helloWorld = require('./helloWorld');
|
||||
|
||||
test('says "Hello, World!"', function() {
|
||||
expect(helloWorld()).toBe("Hello, World!");
|
||||
});
|
File diff suppressed because it is too large
Load Diff
15
package.json
15
package.json
|
@ -14,16 +14,21 @@
|
|||
},
|
||||
"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"
|
||||
"eslint": "^8.47.0",
|
||||
"eslint-config-airbnb-base": "^15.0.0",
|
||||
"eslint-plugin-import": "^2.28.1",
|
||||
"jest": "^29.6.4",
|
||||
"jest-cli": "^29.6.4"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "jest"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"root": true
|
||||
},
|
||||
"jest": {
|
||||
"testPathIgnorePatterns": [
|
||||
"generator-exercise/"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
const palindromes = function () {};
|
||||
|
||||
};
|
||||
|
||||
module.exports = palindromes;
|
|
@ -1,5 +0,0 @@
|
|||
function pigLatin(string) {
|
||||
|
||||
};
|
||||
|
||||
module.exports = pigLatin;
|
|
@ -1,12 +0,0 @@
|
|||
const ftoc = function() {
|
||||
|
||||
};
|
||||
|
||||
const ctof = function() {
|
||||
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
ftoc,
|
||||
ctof
|
||||
};
|
|
@ -1,25 +0,0 @@
|
|||
const {ftoc, ctof} = require('./tempConversion')
|
||||
|
||||
describe('ftoc', () => {
|
||||
test('works', () => {
|
||||
expect(ftoc(32)).toEqual(0);
|
||||
});
|
||||
test.skip('rounds to 1 decimal', () => {
|
||||
expect(ftoc(100)).toEqual(37.8);
|
||||
});
|
||||
test.skip('works with negatives', () => {
|
||||
expect(ftoc(-100)).toEqual(-73.3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ctof', () => {
|
||||
test.skip('works', () => {
|
||||
expect(ctof(0)).toEqual(32);
|
||||
});
|
||||
test.skip('rounds to 1 decimal', () => {
|
||||
expect(ctof(73.2)).toEqual(163.8);
|
||||
});
|
||||
test.skip('works with negatives', () => {
|
||||
expect(ctof(-10)).toEqual(14);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue