10000 Merge pull request #368 from cats256/patch-1 · kwcai/javascript-exercises@cdba6da · GitHub
[go: up one dir, main page]

Skip to content

Commit cdba6da

Browse files
Merge pull request TheOdinProject#368 from cats256/patch-1
Update sumAll-solution.js swap algorithm to standard method
2 parents 191a43a + f5f6efa commit cdba6da

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

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;

0 commit comments

Comments
 (0)
0