Last active
April 5, 2022 12:24
-
-
Save sqveeze/f2c5f6596e7200e7e1f3bff542fc4339 to your computer and use it in GitHub Desktop.
Sum all number from 0 to X
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sum all number from 1 to X using NO loops. | |
// For example i want to sum all number from 0 to 100 with just one function call. (No loops inside function too!!) | |
// Answer is in line 100 | |
sum(100); | |
const sum = function(to: number) { | |
console.log(to / 2 * (to + 1)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment