8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3ecdab9 commit 5513be5Copy full SHA for 5513be5
05_sumAll/solution/sumAll-solution.js
@@ -1,8 +1,16 @@
1
const sumAll = function (min, max) {
2
if (!Number.isInteger(min) || !Number.isInteger(max)) return "ERROR";
3
if (min < 0 || max < 0) return "ERROR";
4
- if (min > max) [min, max] = [max, min];
+ if (min > max) {
5
+ const temp = min;
6
+ min = max;
7
+ max = temp;
8
+ }
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
+
14
let sum = 0;
15
for (let i = min; i <= max; i++) {
16
sum += i;
0 commit comments