odin-default-js-exercises/05_sumAll/solution/sumAll-solution.js

17 lines
343 B
JavaScript
Raw Permalink Normal View History

2022-02-20 19:07:44 +00:00
const sumAll = function (min, max) {
2023-01-21 17:53:41 +00:00
if (!Number.isInteger(min) || !Number.isInteger(max)) return "ERROR";
if (min < 0 || max < 0) 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;
2022-02-20 19:07:44 +00:00
};
module.exports = sumAll;