Files
30-seconds-of-code/snippets/js/s/sum-of-numbers-until-n.md
Angelos Chalaris 9d032ce05e Rename js snippets
2023-05-19 20:23:47 +03:00

358 B

title, type, language, tags, cover, dateModified
title type language tags cover dateModified
Sum of numbers until n snippet javascript
math
blue-flower 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