Update sumAll-solution.js
Change the swapping algorithm to the standard way of swapping using array restructuring.
This commit is contained in:
parent
5a7cd9b162
commit
415ff48c20
|
@ -1,11 +1,8 @@
|
||||||
const sumAll = function (min, max) {
|
const sumAll = function (min, max) {
|
||||||
if (!Number.isInteger(min) || !Number.isInteger(max)) return "ERROR";
|
if (!Number.isInteger(min) || !Number.isInteger(max)) return "ERROR";
|
||||||
if (min < 0 || max < 0) return "ERROR";
|
if (min < 0 || max < 0) return "ERROR";
|
||||||
if (min > max) {
|
if (min > max) [min, max] = [max, min];
|
||||||
const temp = min;
|
|
||||||
min = max;
|
|
||||||
max = temp;
|
|
||||||
}
|
|
||||||
let sum = 0;
|
let sum = 0;
|
||||||
for (let i = min; i < max + 1; i++) {
|
for (let i = min; i < max + 1; i++) {
|
||||||
sum += i;
|
sum += i;
|
||||||
|
|
Loading…
Reference in New Issue