Skip to content

Commit 415ff48

Browse files
authored
Update sumAll-solution.js
Change the swapping algorithm to the standard way of swapping using array restructuring.
1 parent 5a7cd9b commit 415ff48

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

05_sumAll/solution/sumAll-solution.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
const sumAll = function (min, max) {
22
if (!Number.isInteger(min) || !Number.isInteger(max)) return "ERROR";
33
if (min < 0 || max < 0) return "ERROR";
4-
if (min > max) {
5-
const temp = min;
6-
min = max;
7-
max = temp;
8-
}
4+
if (min > max) [min, max] = [max, min];
5+
96
let sum = 0;
107
for (let i = min; i < max + 1; i++) {
118
sum += i;

0 commit comments

Comments
 (0)