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

15 lines
341 B
JavaScript
Raw Normal View History

2024-01-05 20:37:06 +00:00
const sumAll = function(a, b) {
2024-01-05 20:56:46 +00:00
if (a < 0 || b < 0 || typeof(a) != "number"|| typeof(b) != "number") {
2024-01-05 20:46:07 +00:00
return "ERROR";
}
2024-01-05 20:43:56 +00:00
let c, sum = 0;
for ((a > b) ? (i = b, c = a)
: (i = a, c = b); i <= c; i++) {
2024-01-05 20:37:06 +00:00
sum += i;
}
return sum;
};
// Do not edit below this line
module.exports = sumAll;