DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Discussion on: What’s your alternative solution? Challenge #5

Collapse
shankarsridhar profile image
Shankar Sridhar • Edited on
const sumFrom1ToN = n => (n * (n + 1)) / 2;

This will work with any number of input numbers, as long as input starts from 1 to n and they are all integers.

Sample Runs:
sumFrom1ToN(10); // 55
sumFrom1ToN(5); // 15