odin-default-js-exercises/sumAll/sumAll.js

17 lines
342 B
JavaScript
Raw Normal View History

2017-12-15 19:43:38 +00:00
const sumAll = function(min, max) {
if (!Number.isInteger(min) || !Number.isInteger(max)) return "ERROR";
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;