8000 Merge branch 'TheOdinProject:main' into fix_Fibonacci_README · gitwinst/javascript-exercises@6d5f678 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6d5f678

Browse files
authored
Merge branch 'TheOdinProject:main' into fix_Fibonacci_README
2 parents 631d249 + cdba6da commit 6d5f678

File tree

10 files changed

+84
-74
lines changed

10 files changed

+84
-74
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ assignees: ""
99
<!-- 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. -->
1010

1111
Complete the following REQUIRED checkboxes:
12-
- [ ] I have thoroughly read and understand [The Odin Project Contributing Guide](https://github.com/TheOdinProject/theodinproject/blob/main/CONTRIBUTING.md)
12+
- [ ] I have thoroughly read and understand [The Odin Project Contributing Guide](https://github.com/TheOdinProject/.github/blob/main/CONTRIBUTING.md)
1313
- [ ] 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`
1414

1515
The following checkbox is OPTIONAL:

.github/ISSUE_TEMPLATE/feature_request.md

Lines changed: 3 additions & 3 deletions
21
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ assignees: ""
99
<!-- 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. -->
1010

1111
Complete the following REQUIRED checkboxes:
12-
- [ ] I have thoroughly read and understand [The Odin Project Contributing Guide](https://github.com/TheOdinProject/theodinproject/blob/main/CONTRIBUTING.md)
12+
- [ ] I have thoroughly read and understand [The Odin Project Contributing Guide](https://github.com/TheOdinProject/.github/blob/main/CONTRIBUTING.md)
1313
- [ ] The title of this issue follows the `location for request: brief description of request` format, e.g. `Exercises: Add exercise on XYZ`
1414

1515
The following checkbox is OPTIONAL:
@@ -19,8 +19,8 @@ The following checkbox is OPTIONAL:
1919
<hr>
2020

21
**1. Description of the Feature Request:**
22-
<!--
23-
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.
22+
<!--
23+
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.
2424
-->
2525

2626

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ Closes #XXXXX
2424

2525
## Pull Request Requirements
2626
<!-- 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. -->
27-
- [ ] I have thoroughly read and understand [The Odin Project Contributing Guide](https://github.com/TheOdinProject/theodinproject/blob/main/CONTRIBUTING.md)
27+
- [ ] I have thoroughly read and understand [The Odin Project Contributing Guide](https://github.com/TheOdinProject/.github/blob/main/CONTRIBUTING.md)
2828
- [ ] The title of this PR follows the `location of change: brief description of change` format, e.g. `01_helloWorld: Update test cases`
2929
- [ ] The `Because` section summarizes the reason for this PR
3030
- [ ] The `This PR` section has a bullet point list describing the changes in this PR
3131
- [ ] If this PR addresses an open issue, it is linked in the `Issue` section
32-
- [ ] 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).
32+
- [ ] If this PR includes any changes that affect the solution of an exercise, I've also updated the solution in the `/solutions` folder

05_sumAll/solution/sumAll-solution.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ const sumAll = function (min, max) {
66
min = max;
77
max = temp;
88
}
9+
10+
// An alternative way to swap the values of min and max like above is to use the array destructuring syntax.
11+
// Here's an optional article on it: https://www.freecodecamp.org/news/array-destructuring-in-es6-30e398f21d10/
12+
// if (min > max) [min, max] = [max, min];
13+
914
let sum = 0;
10-
for (let i = min; i < max + 1; i++) {
15+
for (let i = min; i <= max; i++) {
1116
sum += i;
1217
}
1318
return sum;

08_calculator/calculator.spec.js

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,77 @@
11
const calculator = require('./calculator');
22

33
describe('add', () => {
4-
test('adds 0 and 0', () => {
5-
expect(calculator.add(0,0)).toBe(0);
6-
});
4+
test('adds 0 and 0', () => {
5+
expect(calculator.add(0, 0)).toBe(0);
6+
});
77

8-
test.skip('adds 2 and 2', () => {
9-
expect(calculator.add(2,2)).toBe(4);
10-
});
8+
test.skip('adds 2 and 2', () => {
9+
expect(calculator.add(2, 2)).toBe(4);
10+
});
1111

12-
test.skip('adds positive numbers', () => {
13-
expect(calculator.add(2,6)).toBe(8);
14-
});
12+
test.skip('adds positive numbers', () => {
13+
expect(calculator.add(2, 6)).toBe(8);
14+
});
1515
});
1616

1717
describe('subtract', () => {
18-
test.skip('subtracts numbers', () => {
19-
expect(calculator.subtract(10,4)).toBe(6);
20-
});
18+
test.skip('subtracts numbers', () => {
19+
expect(calculator.subtract(10, 4)).toBe(6);
20+
});
2121
});
2222

2323
describe('sum', () => {
24-
test.skip('computes the sum of an empty array', () => {
25-
expect(calculator.sum([])).toBe(0);
26-
});
24+
test.skip('computes the sum of an empty array', () => {
25+
expect(calculator.sum([])).toBe(0);
26+
});
2727

28-
test.skip('computes the sum of an array of one number', () => {
29-
expect(calculator.sum([7])).toBe(7);
30-
});
28+
test.skip('computes the sum of an array of one number', () => {
29+
expect(calculator.sum([7])).toBe(7);
30+
});
3131

32-
test.skip('computes the sum of an array of two numbers', () => {
33-
expect(calculator.sum([7,11])).toBe(18);
34-
});
32+
test.skip('computes the sum of an array of two numbers', () => {
33+
expect(calculator.sum([7, 11])).toBe(18);
34+
});
3535

36-
test.skip('computes the sum of an array of many numbers', () => {
37-
expect(calculator.sum([1,3,5,7,9])).toBe(25);
38-
});
36+
test.skip('computes the sum of an array of many numbers', () => {
37+
expect(calculator.sum([1, 3, 5, 7, 9])).toBe(25);
38+
});
3939
});
4040

4141
describe('multiply', () => {
42-
test.skip('multiplies two numbers', () => {
43-
expect(calculator.multiply(2,4)).toBe(8);
44-
});
42+
test.skip('multiplies two numbers', () => {
43+
expect(calculator.multiply([2, 4])).toBe(8);
44+
});
4545

46-
test.skip('multiplies several numbers', () => {
47-
expect(calculator.multiply(2,4,6,8,10,12,14)).toBe(645120);
48-
});
46+
test.skip('multiplies several numbers', () => {
47+
expect(calculator.multiply([2, 4, 6, 8, 10, 12, 14])).toBe(645120);
48+
});
4949
});
5050

5151
describe('power', () => {
52-
test.skip('raises one number to the power of another number', () => {
53-
expect(calculator.power(4,3)).toBe(64); // 4 to third power is 64
54-
});
52+
test.skip('raises one number to the power of another number', () => {
53+
expect(calculator.power(4, 3)).toBe(64); // 4 to third power is 64
54+
});
5555
});
5656

5757
describe('factorial', () => {
58-
test.skip('computes the factorial of 0', () => {
59-
expect(calculator.factorial(0)).toBe(1); // 0! = 1
60-
});
58+
test.skip('computes the factorial of 0', () => {
59+
expect(calculator.factorial(0)).toBe(1); // 0! = 1
60+
});
6161

62-
test.skip('computes the factorial of 1', () => {
63-
expect(calculator.factorial(1)).toBe(1);
64-
});
62+
test.skip('computes the factorial of 1', () => {
63+
expect(calculator.factorial(1)).toBe(1);
64+
});
6565

66-
test.skip('computes the factorial of 2', () => {
67-
expect(calculator.factorial(2)).toBe(2);
68-
});
66+
test.skip('computes the factorial of 2', () => {
67+
expect(calculator.factorial(2)).toBe(2);
68+
});
6969

70-
test.skip('computes the factorial of 5', () => {
71-
expect(calculator.factorial(5)).toBe(120);
72-
});
70+
test.skip('computes the factorial of 5', () => {
71+
expect(calculator.factorial(5)).toBe(120);
72+
});
7373

74-
test.skip('computes the factorial of 10', () => {
75-
expect(calculator.factorial(10)).toBe(3628800);
76-
});
74+
test.skip('computes the factorial of 10', () => {
75+
expect(calculator.factorial(10)).toBe(3628800);
76+
});
7777
});

08_calculator/solution/calculator-solution.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,9 @@ const sum = function (array) {
1010
return array.reduce((total, current) => total + current, 0);
1111
};
1212

13-
const multiply = function(...args){
14-
let product = 1;
15-
for (let i = 0; i < args.length; i++) {
16-
product *= args[i];
17-
}
18-
return product;
19-
};
13+
const multiply = function (array) {
14+
return array.reduce((product, current) => product * current)
15+
};
2016

2117
const power = function (a, b) {
2218
return Math.pow(a, b);
Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
const fibonacci = function(count) {
2-
if (count < 0) return "OOPS"
3-
const fibPart = [0, 1];
4-
for (let index = 1; index < count; index++) {
5-
fibPart.push(fibPart[index] + fibPart[index -1]);
6-
}
7-
return fibPart[count];
2+
if (count < 0) return "OOPS";
3+
if (count === 0) return 0;
4+
5+
let firstPrev = 1;
6+
let secondPrev = 0;
7+
8+
for (let i = 2; i <= count; i++) {
9+
let current = firstPrev + secondPrev;
10+
secondPrev = firstPrev;
11+
firstPrev = current;
12+
}
13+
14+
return firstPrev;
815
};
916

1017
module.exports = fibonacci;

12_findTheOldest/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
Given an array of objects representing people with a birth and death year, return the oldest person.
44

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

12_findTheOldest/findTheOldest.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const findTheOldest = require('./findTheOldest')
22

33
describe('findTheOldest', () => {
4-
test('finds the oldest person!', () => {
4+
test('finds the person with the greatest age!', () => {
55
const people = [
66
{
77
name: "Carly",
@@ -21,7 +21,7 @@ describe('findTheOldest', () => {
2121
]
2222
expect(findTheOldest(people).name).toBe('Ray');
2323
});
24-
test.skip('finds the oldest person if someone is still living', () => {
24+
test.skip('finds the person with the greatest age if someone is still living', () => {
2525
const people = [
2626
{
2727
name: "Carly",
@@ -40,7 +40,7 @@ describe('findTheOldest', () => {
4040
]
4141
expect(findTheOldest(people).name).toBe('Ray');
4242
});
43-
test.skip('finds the oldest person if the OLDEST is still living', () => {
43+
test.skip('finds the person with the greatest age if the OLDEST is still living', () => {
4444
const people = [
4545
{
4646
name: "Carly",

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ These JavaScript exercises are intended to complement the JavaScript content on
66

77
## Contributing
88

9-
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.
9+
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).
1010

1111
## How To Use These Exercises
1212

@@ -34,4 +34,4 @@ The first exercise, `helloWorld`, will walk you through the process in-depth.
3434

3535
## Debugging
3636

37-
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.
37+
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.

0 commit comments

Comments
 (0)
0