Files
30-seconds-of-code/snippets/sum-n.md
Angelos Chalaris 61200d90c4 Kebab file names
2023-04-27 21:58:35 +03:00

357 B

title, tags, cover, firstSeen, lastUpdated
title tags cover firstSeen lastUpdated
Sum of numbers until n math blue-flower 2020-10-08T16:52:55+03:00 2020-10-22T20:24:30+03:00

Sums all the numbers between 1 and n.

  • Use the formula (n * (n + 1)) / 2 to get the sum of all the numbers between 1 and n.
const sumN = n => (n * (n + 1)) / 2;
sumN(100); // 5050