odin-js-fundamentals-part-4/05_sumAll/sumAll.js

15 lines
341 B
JavaScript

const sumAll = function(a, b) {
if (a < 0 || b < 0 || typeof(a) != "number"|| typeof(b) != "number") {
return "ERROR";
}
let c, sum = 0;
for ((a > b) ? (i = b, c = a)
: (i = a, c = b); i <= c; i++) {
sum += i;
}
return sum;
};
// Do not edit below this line
module.exports = sumAll;