2017-12-15 11:43:38 -08:00
|
|
|
const sumAll = function(min, max) {
|
|
|
|
if (min < 0 || max < 0) return "ERROR";
|
|
|
|
if (typeof min !== "number" || typeof max !== "number") return "ERROR";
|
|
|
|
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 06:26:01 -07:00
|
|
|
|
2017-12-15 11:43:38 -08:00
|
|
|
module.exports = sumAll;
|