Merge branch 'TheOdinProject:main' into fix_Fibonacci_README

This commit is contained in:
Rushil Jalal 2023-07-30 10:42:45 +05:30 committed by GitHub
commit 6d5f678ffc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 84 additions and 74 deletions

View File

@ -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. --> <!-- 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: Complete the following REQUIRED checkboxes:
- [ ] I have thoroughly read and understand [The Odin Project Contributing Guide](https://github.com/TheOdinProject/theodinproject/blob/main/CONTRIBUTING.md) - [ ] 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 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: The following checkbox is OPTIONAL:

View File

@ -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. --> <!-- 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: Complete the following REQUIRED checkboxes:
- [ ] I have thoroughly read and understand [The Odin Project Contributing Guide](https://github.com/TheOdinProject/theodinproject/blob/main/CONTRIBUTING.md) - [ ] 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 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: The following checkbox is OPTIONAL:
@ -19,8 +19,8 @@ The following checkbox is OPTIONAL:
<hr> <hr>
**1. Description of the Feature Request:** **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.
--> -->

View File

@ -24,9 +24,9 @@ Closes #XXXXX
## Pull Request Requirements ## 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. --> <!-- 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/theodinproject/blob/main/CONTRIBUTING.md) - [ ] 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 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 `Because` section summarizes the reason for this PR
- [ ] The `This PR` section has a bullet point list describing the changes in 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 addresses an open issue, it is linked in the `Issue` section
- [ ] 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). - [ ] If this PR includes any changes that affect the solution of an exercise, I've also updated the solution in the `/solutions` folder

View File

@ -6,8 +6,13 @@ const sumAll = function (min, max) {
min = max; min = max;
max = temp; 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; let sum = 0;
for (let i = min; i < max + 1; i++) { for (let i = min; i <= max; i++) {
sum += i; sum += i;
} }
return sum; return sum;

View File

@ -1,77 +1,77 @@
const calculator = require('./calculator'); const calculator = require('./calculator');
describe('add', () => { describe('add', () => {
test('adds 0 and 0', () => { test('adds 0 and 0', () => {
expect(calculator.add(0,0)).toBe(0); expect(calculator.add(0, 0)).toBe(0);
}); });
test.skip('adds 2 and 2', () => { test.skip('adds 2 and 2', () => {
expect(calculator.add(2,2)).toBe(4); expect(calculator.add(2, 2)).toBe(4);
}); });
test.skip('adds positive numbers', () => { test.skip('adds positive numbers', () => {
expect(calculator.add(2,6)).toBe(8); expect(calculator.add(2, 6)).toBe(8);
}); });
}); });
describe('subtract', () => { describe('subtract', () => {
test.skip('subtracts numbers', () => { test.skip('subtracts numbers', () => {
expect(calculator.subtract(10,4)).toBe(6); expect(calculator.subtract(10, 4)).toBe(6);
}); });
}); });
describe('sum', () => { describe('sum', () => {
test.skip('computes the sum of an empty array', () => { test.skip('computes the sum of an empty array', () => {
expect(calculator.sum([])).toBe(0); expect(calculator.sum([])).toBe(0);
}); });
test.skip('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); expect(calculator.sum([7])).toBe(7);
}); });
test.skip('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); expect(calculator.sum([7, 11])).toBe(18);
}); });
test.skip('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); expect(calculator.sum([1, 3, 5, 7, 9])).toBe(25);
}); });
}); });
describe('multiply', () => { describe('multiply', () => {
test.skip('multiplies two numbers', () => { test.skip('multiplies two numbers', () => {
expect(calculator.multiply(2,4)).toBe(8); expect(calculator.multiply([2, 4])).toBe(8);
}); });
test.skip('multiplies several numbers', () => { test.skip('multiplies several numbers', () => {
expect(calculator.multiply(2,4,6,8,10,12,14)).toBe(645120); expect(calculator.multiply([2, 4, 6, 8, 10, 12, 14])).toBe(645120);
}); });
}); });
describe('power', () => { describe('power', () => {
test.skip('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 expect(calculator.power(4, 3)).toBe(64); // 4 to third power is 64
}); });
}); });
describe('factorial', () => { describe('factorial', () => {
test.skip('computes the factorial of 0', () => { test.skip('computes the factorial of 0', () => {
expect(calculator.factorial(0)).toBe(1); // 0! = 1 expect(calculator.factorial(0)).toBe(1); // 0! = 1
}); });
test.skip('computes the factorial of 1', () => { test.skip('computes the factorial of 1', () => {
expect(calculator.factorial(1)).toBe(1); expect(calculator.factorial(1)).toBe(1);
}); });
test.skip('computes the factorial of 2', () => { test.skip('computes the factorial of 2', () => {
expect(calculator.factorial(2)).toBe(2); expect(calculator.factorial(2)).toBe(2);
}); });
test.skip('computes the factorial of 5', () => { test.skip('computes the factorial of 5', () => {
expect(calculator.factorial(5)).toBe(120); expect(calculator.factorial(5)).toBe(120);
}); });
test.skip('computes the factorial of 10', () => { test.skip('computes the factorial of 10', () => {
expect(calculator.factorial(10)).toBe(3628800); expect(calculator.factorial(10)).toBe(3628800);
}); });
}); });

View File

@ -10,13 +10,9 @@ const sum = function (array) {
return array.reduce((total, current) => total + current, 0); return array.reduce((total, current) => total + current, 0);
}; };
const multiply = function(...args){ const multiply = function (array) {
let product = 1; return array.reduce((product, current) => product * current)
for (let i = 0; i < args.length; i++) { };
product *= args[i];
}
return product;
};
const power = function (a, b) { const power = function (a, b) {
return Math.pow(a, b); return Math.pow(a, b);

View File

@ -1,10 +1,17 @@
const fibonacci = function(count) { const fibonacci = function(count) {
if (count < 0) return "OOPS" if (count < 0) return "OOPS";
const fibPart = [0, 1]; if (count === 0) return 0;
for (let index = 1; index < count; index++) {
fibPart.push(fibPart[index] + fibPart[index -1]); let firstPrev = 1;
} let secondPrev = 0;
return fibPart[count];
for (let i = 2; i <= count; i++) {
let current = firstPrev + secondPrev;
secondPrev = firstPrev;
firstPrev = current;
}
return firstPrev;
}; };
module.exports = fibonacci; module.exports = fibonacci;

View File

@ -2,7 +2,9 @@
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.
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 ## Hints
- You should return the whole person object, but the tests mostly just check to make sure the name is correct. - You should return the whole person object, but the tests mostly just check to make sure the name is correct.
- this can be done with a couple of chained array methods, or by using `reduce`. - This can be done with a couple of chained array methods, or by using `reduce`.
- One of the tests checks for people with no death-date.. use JavaScript's Date function to get their age as of today. - One of the tests checks for people with no death-date.. use JavaScript's Date function to get their age as of today.

View File

@ -1,7 +1,7 @@
const findTheOldest = require('./findTheOldest') const findTheOldest = require('./findTheOldest')
describe('findTheOldest', () => { describe('findTheOldest', () => {
test('finds the oldest person!', () => { test('finds the person with the greatest age!', () => {
const people = [ const people = [
{ {
name: "Carly", name: "Carly",
@ -21,7 +21,7 @@ describe('findTheOldest', () => {
] ]
expect(findTheOldest(people).name).toBe('Ray'); 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 = [ const people = [
{ {
name: "Carly", name: "Carly",
@ -40,7 +40,7 @@ describe('findTheOldest', () => {
] ]
expect(findTheOldest(people).name).toBe('Ray'); 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 = [ const people = [
{ {
name: "Carly", name: "Carly",

View File

@ -6,7 +6,7 @@ These JavaScript exercises are intended to complement the JavaScript content on
## Contributing ## 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/theodinproject/blob/main/CONTRIBUTING.md) in our main TOP repo. 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 ## How To Use These Exercises
@ -34,4 +34,4 @@ The first exercise, `helloWorld`, will walk you through the process in-depth.
## Debugging ## 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 `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. 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.