Find the sum of consecutive whole numbers w/o using loop in JavaScript
Posted
by Zlatev
on Stack Overflow
See other posts from Stack Overflow
or by Zlatev
Published on 2010-05-16T08:28:48Z
Indexed on
2010/05/16
8:30 UTC
Read the original article
Hit count: 278
JavaScript
|math
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.
© Stack Overflow or respective owner