diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 4c4571c..186b427 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -9,7 +9,7 @@ assignees: "" 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 following checkbox is OPTIONAL: diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 4814cc2..13d7ae0 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -9,7 +9,7 @@ assignees: "" 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 following checkbox is OPTIONAL: @@ -19,8 +19,8 @@ The following checkbox is OPTIONAL:
**1. Description of the Feature Request:** - diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index d3ee065..b53f0f1 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -24,9 +24,9 @@ Closes #XXXXX ## Pull Request Requirements -- [ ] 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 `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 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 diff --git a/05_sumAll/solution/sumAll-solution.js b/05_sumAll/solution/sumAll-solution.js index 50c78fe..ae01a5b 100644 --- a/05_sumAll/solution/sumAll-solution.js +++ b/05_sumAll/solution/sumAll-solution.js @@ -6,8 +6,13 @@ 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 + 1; i++) { + for (let i = min; i <= max; i++) { sum += i; } return sum; diff --git a/08_calculator/calculator.spec.js b/08_calculator/calculator.spec.js index 3507452..48b08c9 100644 --- a/08_calculator/calculator.spec.js +++ b/08_calculator/calculator.spec.js @@ -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); + }); }); diff --git a/08_calculator/solution/calculator-solution.js b/08_calculator/solution/calculator-solution.js index ab39a60..b195387 100644 --- a/08_calculator/solution/calculator-solution.js +++ b/08_calculator/solution/calculator-solution.js @@ -10,13 +10,9 @@ const sum = function (array) { return array.reduce((total, current) => total + current, 0); }; -const multiply = function(...args){ - let product = 1; - for (let i = 0; i < args.length; i++) { - product *= args[i]; - } - return product; - }; +const multiply = function (array) { + return array.reduce((product, current) => product * current) +}; const power = function (a, b) { return Math.pow(a, b); diff --git a/10_fibonacci/solution/fibonacci-solution.js b/10_fibonacci/solution/fibonacci-solution.js index 010131c..acdd1e0 100644 --- a/10_fibonacci/solution/fibonacci-solution.js +++ b/10_fibonacci/solution/fibonacci-solution.js @@ -1,10 +1,17 @@ const fibonacci = function(count) { - if (count < 0) return "OOPS" - const fibPart = [0, 1]; - for (let index = 1; index < count; index++) { - fibPart.push(fibPart[index] + fibPart[index -1]); - } - return fibPart[count]; + 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; }; module.exports = fibonacci; diff --git a/12_findTheOldest/README.md b/12_findTheOldest/README.md index 92d0bf3..087f45e 100644 --- a/12_findTheOldest/README.md +++ b/12_findTheOldest/README.md @@ -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. diff --git a/12_findTheOldest/findTheOldest.spec.js b/12_findTheOldest/findTheOldest.spec.js index 06aec70..732faaa 100644 --- a/12_findTheOldest/findTheOldest.spec.js +++ b/12_findTheOldest/findTheOldest.spec.js @@ -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", diff --git a/README.md b/README.md index 544fecc..2b2e3d5 100644 --- a/README.md +++ b/README.md @@ -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/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 @@ -34,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 `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 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.