Merge branch 'TheOdinProject:main' into fix_Fibonacci_README
This commit is contained in:
commit
6d5f678ffc
|
@ -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:
|
||||||
|
|
|
@ -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:
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -40,11 +40,11 @@ describe('sum', () => {
|
||||||
|
|
||||||
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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -10,12 +10,8 @@ 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) {
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
for (let i = 2; i <= count; i++) {
|
||||||
|
let current = firstPrev + secondPrev;
|
||||||
|
secondPrev = firstPrev;
|
||||||
|
firstPrev = current;
|
||||||
}
|
}
|
||||||
return fibPart[count];
|
|
||||||
|
return firstPrev;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = fibonacci;
|
module.exports = fibonacci;
|
||||||
|
|
|
@ -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.
|
||||||
|
|
|
@ -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",
|
||||||
|
|
|
@ -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.
|
||||||
|
|
Loading…
Reference in New Issue