Files
30-seconds-of-code/snippets/sumN.md
Isabelle Viktoria Maciohsek 8bf67754ce Make expertise a field
2022-03-01 20:21:45 +02:00

358 B

title, tags, expertise, firstSeen, lastUpdated
title tags expertise firstSeen lastUpdated
Sum of numbers until n math beginner 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