Find the sum of consecutive whole numbers w/o using loop in JavaScript
- by Zlatev
I'm looking for a method to do calculations like:
function sumIntegerUpTo(number) {
return 1+2+3+...+number;
}
If you pass number as 5 function should return the sum of 1+2+3+4+5. I'm wondering if it's possible to do without loops.