From 197a716eb0136bb32d952c8d2a7e167715f55cc6 Mon Sep 17 00:00:00 2001 From: Ryan McEntire <107779145+RyanMcEntire@users.noreply.github.com> Date: Thu, 6 Apr 2023 18:41:30 -0600 Subject: [PATCH 01/19] reword test description to be less tautological and more clear --- 12_findTheOldest/findTheOldest.spec.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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", From 37f85db108805003ecaba6131c8f8ec3d596176a Mon Sep 17 00:00:00 2001 From: Manon Date: Sat, 1 Jul 2023 16:09:59 +0200 Subject: [PATCH 02/19] JS exercises README: change shortcuts to kbd format --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 544fecc..e594688 100644 --- a/README.md +++ b/README.md @@ -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. From 415ff48c20a60adaeca34a7ec0baa0b54e374824 Mon Sep 17 00:00:00 2001 From: cats256 <59489624+cats256@users.noreply.github.com> Date: Mon, 3 Jul 2023 22:52:46 -0500 Subject: [PATCH 03/19] Update sumAll-solution.js Change the swapping algorithm to the standard way of swapping using array restructuring. --- 05_sumAll/solution/sumAll-solution.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/05_sumAll/solution/sumAll-solution.js b/05_sumAll/solution/sumAll-solution.js index 50c78fe..c4b38e3 100644 --- a/05_sumAll/solution/sumAll-solution.js +++ b/05_sumAll/solution/sumAll-solution.js @@ -1,11 +1,8 @@ const sumAll = function (min, max) { if (!Number.isInteger(min) || !Number.isInteger(max)) return "ERROR"; if (min < 0 || max < 0) return "ERROR"; - if (min > max) { - const temp = min; - min = max; - max = temp; - } + if (min > max) [min, max] = [max, min]; + let sum = 0; for (let i = min; i < max + 1; i++) { sum += i; From 3ecdab95312793d05d882fcc35220011abb7d7e7 Mon Sep 17 00:00:00 2001 From: cats256 <59489624+cats256@users.noreply.github.com> Date: Mon, 3 Jul 2023 22:58:19 -0500 Subject: [PATCH 04/19] Update sumAll-solution.js --- 05_sumAll/solution/sumAll-solution.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/05_sumAll/solution/sumAll-solution.js b/05_sumAll/solution/sumAll-solution.js index c4b38e3..08daf58 100644 --- a/05_sumAll/solution/sumAll-solution.js +++ b/05_sumAll/solution/sumAll-solution.js @@ -4,7 +4,7 @@ const sumAll = function (min, max) { 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; From 075fe8eea2c304417b3142a6a1e2660d5fe15d3c Mon Sep 17 00:00:00 2001 From: cats256 <59489624+cats256@users.noreply.github.com> Date: Tue, 4 Jul 2023 11:38:40 -0500 Subject: [PATCH 05/19] Reformat test parameters for consistency --- 08_calculator/calculator.spec.js | 30 +++++++++---------- 08_calculator/solution/calculator-solution.js | 4 +-- .../solution/calculator-solution.spec.js | 20 ++++++------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/08_calculator/calculator.spec.js b/08_calculator/calculator.spec.js index 3507452..7cd2314 100644 --- a/08_calculator/calculator.spec.js +++ b/08_calculator/calculator.spec.js @@ -2,55 +2,55 @@ const calculator = require('./calculator'); describe('add', () => { 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', () => { - expect(calculator.add(2,2)).toBe(4); + expect(calculator.add(2, 2)).toBe(4); }); test.skip('adds positive numbers', () => { - expect(calculator.add(2,6)).toBe(8); + expect(calculator.add(2, 6)).toBe(8); }); }); describe('subtract', () => { test.skip('subtracts numbers', () => { - expect(calculator.subtract(10,4)).toBe(6); + 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 parameter', () => { + 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 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 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 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); + expect(calculator.multiply(2, 4)).toBe(8); }); 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', () => { 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 }); }); diff --git a/08_calculator/solution/calculator-solution.js b/08_calculator/solution/calculator-solution.js index ab39a60..b6b7cf7 100644 --- a/08_calculator/solution/calculator-solution.js +++ b/08_calculator/solution/calculator-solution.js @@ -6,8 +6,8 @@ const subtract = function (a, b) { return a - b; }; -const sum = function (array) { - return array.reduce((total, current) => total + current, 0); +const sum = function (...args) { + return args.reduce((total, current) => total + current, 0); }; const multiply = function(...args){ diff --git a/08_calculator/solution/calculator-solution.spec.js b/08_calculator/solution/calculator-solution.spec.js index 453707c..c99993b 100644 --- a/08_calculator/solution/calculator-solution.spec.js +++ b/08_calculator/solution/calculator-solution.spec.js @@ -21,30 +21,30 @@ describe('subtract', () => { }); describe('sum', () => { - test('computes the sum of an empty array', () => { - expect(calculator.sum([])).toBe(0); + test('computes the sum of an empty parameter', () => { + expect(calculator.sum()).toBe(0); }); - test('computes the sum of an array of one number', () => { - expect(calculator.sum([7])).toBe(7); + test('computes the sum of one number', () => { + expect(calculator.sum(7)).toBe(7); }); - test('computes the sum of an array of two numbers', () => { - expect(calculator.sum([7, 11])).toBe(18); + test('computes the sum of two numbers', () => { + expect(calculator.sum(7, 11)).toBe(18); }); - test('computes the sum of an array of many numbers', () => { - expect(calculator.sum([1, 3, 5, 7, 9])).toBe(25); + test('computes the sum of many numbers', () => { + expect(calculator.sum(1, 3, 5, 7, 9)).toBe(25); }); }); describe('multiply', () => { test('multiplies two numbers', () => { - expect(calculator.multiply([2, 4])).toBe(8); + expect(calculator.multiply(2, 4)).toBe(8); }); test('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); }); }); From 03e52ea9ee6a5c323d61d71c7164177e5b47372b Mon Sep 17 00:00:00 2001 From: cats256 <59489624+cats256@users.noreply.github.com> Date: Tue, 4 Jul 2023 11:55:08 -0500 Subject: [PATCH 06/19] Improve sum and multiply functions solution code --- 08_calculator/solution/calculator-solution.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/08_calculator/solution/calculator-solution.js b/08_calculator/solution/calculator-solution.js index b6b7cf7..43af44f 100644 --- a/08_calculator/solution/calculator-solution.js +++ b/08_calculator/solution/calculator-solution.js @@ -7,16 +7,12 @@ const subtract = function (a, b) { }; const sum = function (...args) { - return args.reduce((total, current) => total + current, 0); + return args.reduce((sum, curr) => sum + curr, 0); }; const multiply = function(...args){ - let product = 1; - for (let i = 0; i < args.length; i++) { - product *= args[i]; - } - return product; - }; + return args.reduce((product, curr) => product * curr) +}; const power = function (a, b) { return Math.pow(a, b); From 76551b0e8a8ce094df4413056151654e49596b8f Mon Sep 17 00:00:00 2001 From: cats256 <59489624+cats256@users.noreply.github.com> Date: Tue, 4 Jul 2023 12:07:04 -0500 Subject: [PATCH 07/19] Update fibonacci-solution.js Better O(n) time --- 10_fibonacci/solution/fibonacci-solution.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/10_fibonacci/solution/fibonacci-solution.js b/10_fibonacci/solution/fibonacci-solution.js index 010131c..e040ede 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 first_prev = 1; + let second_prev = 0; + + for (let i = 2; i <= count; i++) { + let curr = first_prev + second_prev; + second_prev = first_prev; + first_prev = curr; + } + + return first_prev; }; module.exports = fibonacci; From bab1364ea84ce6f758edcfff6a404b6cfbff111f Mon Sep 17 00:00:00 2001 From: Asartea <76259120+Asartea@users.noreply.github.com> Date: Wed, 5 Jul 2023 13:50:13 +0200 Subject: [PATCH 08/19] Fix: change requirement to reflect solutions change --- .github/PULL_REQUEST_TEMPLATE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index d3ee065..cb032be 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -29,4 +29,4 @@ Closes #XXXXX - [ ] 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 From 051c0ed9ca3f3ada167c7ff44bc00bbd3ed1fb8b Mon Sep 17 00:00:00 2001 From: Asartea <76259120+Asartea@users.noreply.github.com> Date: Wed, 5 Jul 2023 14:41:21 +0200 Subject: [PATCH 09/19] CONTRIBUTING.md: repoint contributing links to .github/CONTRIBUTING.md (#371) * repoint contributing links to .github/CONTRIBUTING.md * drop mention of which repo it is --- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- .github/ISSUE_TEMPLATE/feature_request.md | 6 +++--- .github/PULL_REQUEST_TEMPLATE.md | 2 +- README.md | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) 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..83957fc 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -24,7 +24,7 @@ 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 diff --git a/README.md b/README.md index e594688..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 From fcb1c4971ac32995098b49613d5c944257fccb27 Mon Sep 17 00:00:00 2001 From: Nathan <59489624+cats256@users.noreply.github.com> Date: Wed, 5 Jul 2023 09:15:36 -0500 Subject: [PATCH 10/19] Update fibonacci-solution.js --- 10_fibonacci/solution/fibonacci-solution.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/10_fibonacci/solution/fibonacci-solution.js b/10_fibonacci/solution/fibonacci-solution.js index e040ede..1d7d9c6 100644 --- a/10_fibonacci/solution/fibonacci-solution.js +++ b/10_fibonacci/solution/fibonacci-solution.js @@ -2,16 +2,18 @@ const fibonacci = function(count) { if (count < 0) return "OOPS"; if (count === 0) return 0; - let first_prev = 1; - let second_prev = 0; + let firstPrev = 1; + let secondPrev = 0; + // For clarification: curr stands for current. This is standard syntax + for (let i = 2; i <= count; i++) { - let curr = first_prev + second_prev; - second_prev = first_prev; - first_prev = curr; + let curr = firstPrev + secondPrev; + secondPrev = firstPrev; + firstPrev = curr; } - return first_prev; + return firstPrev; }; module.exports = fibonacci; From 51572a070cf04619ea2259c0e6365480e1779989 Mon Sep 17 00:00:00 2001 From: Nathan <59489624+cats256@users.noreply.github.com> Date: Thu, 6 Jul 2023 09:47:20 -0500 Subject: [PATCH 11/19] Update fibonacci-solution.js --- 10_fibonacci/solution/fibonacci-solution.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/10_fibonacci/solution/fibonacci-solution.js b/10_fibonacci/solution/fibonacci-solution.js index 1d7d9c6..acdd1e0 100644 --- a/10_fibonacci/solution/fibonacci-solution.js +++ b/10_fibonacci/solution/fibonacci-solution.js @@ -4,13 +4,11 @@ const fibonacci = function(count) { let firstPrev = 1; let secondPrev = 0; - - // For clarification: curr stands for current. This is standard syntax for (let i = 2; i <= count; i++) { - let curr = firstPrev + secondPrev; + let current = firstPrev + secondPrev; secondPrev = firstPrev; - firstPrev = curr; + firstPrev = current; } return firstPrev; From e6c4530aa9521155bbdeeea95322998ee2ddbef5 Mon Sep 17 00:00:00 2001 From: Roberra Aklilu <130805303+Roberra0@users.noreply.github.com> Date: Mon, 10 Jul 2023 17:09:29 -0700 Subject: [PATCH 12/19] Update ex12_findTheOldest README.md Added clarification to instruct learner to look in test case to understand object structure --- 12_findTheOldest/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/12_findTheOldest/README.md b/12_findTheOldest/README.md index 92d0bf3..55bbdf5 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 end of these exercises, 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. From 100f952f7aa9e91d0fe114ea5a4d33790875e141 Mon Sep 17 00:00:00 2001 From: Roberra Aklilu <130805303+Roberra0@users.noreply.github.com> Date: Mon, 10 Jul 2023 17:21:52 -0700 Subject: [PATCH 13/19] Update README.md with minor word change --- 12_findTheOldest/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/12_findTheOldest/README.md b/12_findTheOldest/README.md index 55bbdf5..087f45e 100644 --- a/12_findTheOldest/README.md +++ b/12_findTheOldest/README.md @@ -2,7 +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 end of these exercises, 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. +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. From e10ee035ad5ab313802ffd262642446bbd49bae1 Mon Sep 17 00:00:00 2001 From: Will <59489624+cats256@users.noreply.github.com> Date: Sun, 16 Jul 2023 15:59:50 -0500 Subject: [PATCH 14/19] Update calculator.spec.js --- 08_calculator/calculator.spec.js | 96 ++++++++++++++++---------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/08_calculator/calculator.spec.js b/08_calculator/calculator.spec.js index 7cd2314..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 parameter', () => { - 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 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 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 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); + }); }); From f855eb51b25eaf043f903a66b90e0f7c1a261592 Mon Sep 17 00:00:00 2001 From: Will <59489624+cats256@users.noreply.github.com> Date: Sun, 16 Jul 2023 16:02:03 -0500 Subject: [PATCH 15/19] Update calculator-solution.spec.js --- .../solution/calculator-solution.spec.js | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/08_calculator/solution/calculator-solution.spec.js b/08_calculator/solution/calculator-solution.spec.js index c99993b..453707c 100644 --- a/08_calculator/solution/calculator-solution.spec.js +++ b/08_calculator/solution/calculator-solution.spec.js @@ -21,30 +21,30 @@ describe('subtract', () => { }); describe('sum', () => { - test('computes the sum of an empty parameter', () => { - expect(calculator.sum()).toBe(0); + test('computes the sum of an empty array', () => { + expect(calculator.sum([])).toBe(0); }); - test('computes the sum of one number', () => { - expect(calculator.sum(7)).toBe(7); + test('computes the sum of an array of one number', () => { + expect(calculator.sum([7])).toBe(7); }); - test('computes the sum of two numbers', () => { - expect(calculator.sum(7, 11)).toBe(18); + test('computes the sum of an array of two numbers', () => { + expect(calculator.sum([7, 11])).toBe(18); }); - test('computes the sum of many numbers', () => { - expect(calculator.sum(1, 3, 5, 7, 9)).toBe(25); + test('computes the sum of an array of many numbers', () => { + expect(calculator.sum([1, 3, 5, 7, 9])).toBe(25); }); }); describe('multiply', () => { test('multiplies two numbers', () => { - expect(calculator.multiply(2, 4)).toBe(8); + expect(calculator.multiply([2, 4])).toBe(8); }); test('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); }); }); From 44e39f0412e4ad24001340e8da1848b0c18a66d5 Mon Sep 17 00:00:00 2001 From: Will <59489624+cats256@users.noreply.github.com> Date: Sun, 16 Jul 2023 16:06:25 -0500 Subject: [PATCH 17/19] Update calculator-solution.js --- 08_calculator/solution/calculator-solution.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/08_calculator/solution/calculator-solution.js b/08_calculator/solution/calculator-solution.js index 43af44f..b195387 100644 --- a/08_calculator/solution/calculator-solution.js +++ b/08_calculator/solution/calculator-solution.js @@ -6,12 +6,12 @@ const subtract = function (a, b) { return a - b; }; -const sum = function (...args) { - return args.reduce((sum, curr) => sum + curr, 0); +const sum = function (array) { + return array.reduce((total, current) => total + current, 0); }; -const multiply = function(...args){ - return args.reduce((product, curr) => product * curr) +const multiply = function (array) { + return array.reduce((product, current) => product * current) }; const power = function (a, b) { From 5513be576ae7ce9ab489238093dd26e87adb5575 Mon Sep 17 00:00:00 2001 From: Will <59489624+cats256@users.noreply.github.com> Date: Sat, 29 Jul 2023 15:39:33 -0500 Subject: [PATCH 18/19] Update sumAll-solution.js --- 05_sumAll/solution/sumAll-solution.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/05_sumAll/solution/sumAll-solution.js b/05_sumAll/solution/sumAll-solution.js index 08daf58..9cc35bb 100644 --- a/05_sumAll/solution/sumAll-solution.js +++ b/05_sumAll/solution/sumAll-solution.js @@ -1,8 +1,16 @@ const sumAll = function (min, max) { if (!Number.isInteger(min) || !Number.isInteger(max)) return "ERROR"; if (min < 0 || max < 0) return "ERROR"; - if (min > max) [min, max] = [max, min]; + if (min > max) { + const temp = min; + 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++) { sum += i; From f5f6efae9bf53a57db07544b8068b9c8a02d1955 Mon Sep 17 00:00:00 2001 From: Will <59489624+cats256@users.noreply.github.com> Date: Sat, 29 Jul 2023 15:40:07 -0500 Subject: [PATCH 19/19] Update sumAll-solution.js --- 05_sumAll/solution/sumAll-solution.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/05_sumAll/solution/sumAll-solution.js b/05_sumAll/solution/sumAll-solution.js index 9cc35bb..ae01a5b 100644 --- a/05_sumAll/solution/sumAll-solution.js +++ b/05_sumAll/solution/sumAll-solution.js @@ -1,7 +1,7 @@ const sumAll = function (min, max) { if (!Number.isInteger(min) || !Number.isInteger(max)) return "ERROR"; if (min < 0 || max < 0) return "ERROR"; - if (min > max) { + if (min > max) { const temp = min; min = max; max = temp;