Files
30-seconds-of-code/javascript/snippets/sum-n.md
2023-05-01 22:35:56 +03:00

337 B

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