Merge pull request #368 from cats256/patch-1
Update sumAll-solution.js swap algorithm to standard method
This commit is contained in:
commit
cdba6da97b
|
@ -6,8 +6,13 @@ const sumAll = function (min, max) {
|
||||||
min = max;
|
min = max;
|
||||||
max = temp;
|
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;
|
let sum = 0;
|
||||||
for (let i = min; i < max + 1; i++) {
|
for (let i = min; i <= max; i++) {
|
||||||
sum += i;
|
sum += i;
|
||||||
}
|
}
|
||||||
return sum;
|
return sum;
|
||||||
|
|
Loading…
Reference in New Issue