2017-12-15 19:43:38 +00:00
|
|
|
const sumAll = function(min, max) {
|
2020-10-10 18:06:51 +00:00
|
|
|
if (!Number.isInteger(min) || !Number.isInteger(max)) return "ERROR";
|
2020-06-25 09:58:02 +00:00
|
|
|
if (min < 0 || max < 0) return "ERROR";
|
2017-12-15 19:43:38 +00:00
|
|
|
if (min > max) {
|
|
|
|
const temp = min;
|
|
|
|
min = max;
|
|
|
|
max = temp;
|
|
|
|
}
|
|
|
|
let sum = 0;
|
|
|
|
for (let i = min; i < max + 1; i++) {
|
|
|
|
sum += i;
|
|
|
|
}
|
|
|
|
return sum;
|
|
|
|
};
|
2017-08-24 13:26:01 +00:00
|
|
|
|
2017-12-15 19:43:38 +00:00
|
|
|
module.exports = sumAll;
|