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 1/4] 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 2/4] 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 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 3/4] 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 4/4] 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;