Compare commits
1 Commits
main
...
dependabot
Author | SHA1 | Date |
---|---|---|
dependabot[bot] | 01645c3533 |
|
@ -9,7 +9,7 @@ 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)
|
||||
- [ ] I have thoroughly read and understand [The Odin Project Contributing Guide](https://github.com/TheOdinProject/theodinproject/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:
|
||||
|
|
|
@ -9,7 +9,7 @@ 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)
|
||||
- [ ] I have thoroughly read and understand [The Odin Project Contributing Guide](https://github.com/TheOdinProject/theodinproject/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:
|
||||
|
@ -19,8 +19,8 @@ The following checkbox is OPTIONAL:
|
|||
<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.
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
|
||||
|
||||
|
|
|
@ -24,9 +24,9 @@ Closes #XXXXX
|
|||
|
||||
## 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)
|
||||
- [ ] I have thoroughly read and understand [The Odin Project Contributing Guide](https://github.com/TheOdinProject/theodinproject/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
|
||||
- [ ] If this PR includes changes that needs to be updated on the `solutions` branch, I have created another PR (and linked it to this PR).
|
||||
|
|
|
@ -6,8 +6,5 @@ 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 (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.
|
||||
|
|
|
@ -6,13 +6,8 @@ const sumAll = function (min, max) {
|
|||
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++) {
|
||||
for (let i = min; i < max + 1; i++) {
|
||||
sum += i;
|
||||
}
|
||||
return sum;
|
||||
|
|
|
@ -1,77 +1,77 @@
|
|||
const calculator = require('./calculator');
|
||||
|
||||
describe('add', () => {
|
||||
test('adds 0 and 0', () => {
|
||||
expect(calculator.add(0, 0)).toBe(0);
|
||||
});
|
||||
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 2 and 2', () => {
|
||||
expect(calculator.add(2,2)).toBe(4);
|
||||
});
|
||||
|
||||
test.skip('adds positive numbers', () => {
|
||||
expect(calculator.add(2, 6)).toBe(8);
|
||||
});
|
||||
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);
|
||||
});
|
||||
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 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 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 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);
|
||||
});
|
||||
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 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);
|
||||
});
|
||||
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
|
||||
});
|
||||
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 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 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 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 5', () => {
|
||||
expect(calculator.factorial(5)).toBe(120);
|
||||
});
|
||||
|
||||
test.skip('computes the factorial of 10', () => {
|
||||
expect(calculator.factorial(10)).toBe(3628800);
|
||||
});
|
||||
test.skip('computes the factorial of 10', () => {
|
||||
expect(calculator.factorial(10)).toBe(3628800);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -11,7 +11,9 @@ const sum = function (array) {
|
|||
};
|
||||
|
||||
const multiply = function (array) {
|
||||
return array.reduce((product, current) => product * current)
|
||||
return array.length
|
||||
? array.reduce((accumulator, nextItem) => accumulator * nextItem)
|
||||
: 0;
|
||||
};
|
||||
|
||||
const power = function (a, b) {
|
||||
|
|
|
@ -22,7 +22,4 @@ describe('palindromes', () => {
|
|||
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);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const palindromes = function (string) {
|
||||
const processedString = string.toLowerCase().replace(/[^a-z0-9]/g, "");
|
||||
const processedString = string.toLowerCase().replace(/[^a-z]/g, "");
|
||||
return processedString.split("").reverse().join("") == processedString;
|
||||
};
|
||||
|
||||
|
|
|
@ -24,7 +24,4 @@ describe('palindromes', () => {
|
|||
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);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -2,11 +2,9 @@
|
|||
|
||||
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
|
||||
> 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
|
||||
fibonacci(4) // returns the 4th member of the series: 3 (1, 1, 2, 3)
|
||||
fibonacci(6) // returns 8
|
||||
```
|
||||
|
|
|
@ -16,15 +16,9 @@ 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);
|
||||
});
|
||||
|
|
|
@ -1,34 +1,14 @@
|
|||
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;
|
||||
|
||||
const fibonacci = function (count) {
|
||||
if (count < 0) return "OOPS";
|
||||
if (count === 0) return 0;
|
||||
let a = 0;
|
||||
let b = 1;
|
||||
for (let i = 1; i < count; i++) {
|
||||
const temp = b;
|
||||
b = a + b;
|
||||
a = temp;
|
||||
}
|
||||
return b;
|
||||
};
|
||||
|
||||
// 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;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const fibonacci = require('./fibonacci-solution')
|
||||
const fibonacci = require('./fibonacci-solution');
|
||||
|
||||
describe('fibonacci', () => {
|
||||
test('4th fibonacci number is 3', () => {
|
||||
|
@ -16,22 +16,16 @@ describe('fibonacci', () => {
|
|||
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("doesn't accept negatives", () => {
|
||||
expect(fibonacci(-25)).toBe('OOPS');
|
||||
});
|
||||
test('DOES accept strings', () => {
|
||||
expect(fibonacci("0")).toBe(0);
|
||||
expect(fibonacci('1')).toBe(1);
|
||||
});
|
||||
test('DOES accept strings', () => {
|
||||
expect(fibonacci("1")).toBe(1);
|
||||
expect(fibonacci('2')).toBe(1);
|
||||
});
|
||||
test('DOES accept strings', () => {
|
||||
expect(fibonacci("2")).toBe(1);
|
||||
expect(fibonacci('8')).toBe(21);
|
||||
});
|
||||
test('DOES accept strings', () => {
|
||||
expect(fibonacci("8")).toBe(21);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
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.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const findTheOldest = require('./findTheOldest')
|
||||
|
||||
describe('findTheOldest', () => {
|
||||
test('finds the person with the greatest age!', () => {
|
||||
test('finds the oldest person!', () => {
|
||||
const people = [
|
||||
{
|
||||
name: "Carly",
|
||||
|
@ -21,7 +21,7 @@ describe('findTheOldest', () => {
|
|||
]
|
||||
expect(findTheOldest(people).name).toBe('Ray');
|
||||
});
|
||||
test.skip('finds the person with the greatest age if someone is still living', () => {
|
||||
test.skip('finds the oldest person 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 person with the greatest age if the OLDEST is still living', () => {
|
||||
test.skip('finds the oldest person if the OLDEST is still living', () => {
|
||||
const people = [
|
||||
{
|
||||
name: "Carly",
|
||||
|
|
|
@ -6,7 +6,7 @@ These JavaScript exercises are intended to complement the JavaScript content on
|
|||
|
||||
## 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).
|
||||
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/theodinproject/blob/main/CONTRIBUTING.md) in our main TOP repo.
|
||||
|
||||
## How To Use These Exercises
|
||||
|
||||
|
@ -15,8 +15,7 @@ If you have a suggestion to improve an exercise, an idea for a new exercise, or
|
|||
- 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.)
|
||||
|
||||
- **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.
|
||||
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.
|
||||
|
@ -35,4 +34,4 @@ The first exercise, `helloWorld`, will walk you through the process in-depth.
|
|||
|
||||
## Debugging
|
||||
|
||||
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.
|
||||
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 `ctrl + shift + D`, 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.
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -17,9 +17,9 @@
|
|||
"yeoman-generator"
|
||||
],
|
||||
"devDependencies": {
|
||||
"yeoman-test": "^1.6.0",
|
||||
"yeoman-test": "^7.4.0",
|
||||
"yeoman-assert": "^3.0.0",
|
||||
"nsp": "^3.2.1",
|
||||
"nsp": "^2.6.3",
|
||||
"eslint": "^4.1.0",
|
||||
"eslint-config-xo-space": "^0.16.0",
|
||||
"jest": "^19.0.2",
|
||||
|
@ -28,7 +28,7 @@
|
|||
"dependencies": {
|
||||
"chalk": "^1.1.3",
|
||||
"extend": "^3.0.2",
|
||||
"yeoman-generator": "^1.0.0",
|
||||
"yeoman-generator": "^5.8.0",
|
||||
"yosay": "^2.0.0"
|
||||
},
|
||||
"jest": {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
12
package.json
12
package.json
|
@ -14,11 +14,11 @@
|
|||
},
|
||||
"homepage": "https://github.com/TheOdinProject/javascript-exercises#readme",
|
||||
"devDependencies": {
|
||||
"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"
|
||||
"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"
|
||||
|
@ -26,7 +26,7 @@
|
|||
"eslintConfig": {
|
||||
"root": true
|
||||
},
|
||||
"jest": {
|
||||
"jest": {
|
||||
"testPathIgnorePatterns": [
|
||||
"generator-exercise/"
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue