Skip to content

Instantly share code, notes, and snippets.

@sqveeze
Last active April 5, 2022 12:24
Show Gist options
  • Save sqveeze/f2c5f6596e7200e7e1f3bff542fc4339 to your computer and use it in GitHub Desktop.
Save sqveeze/f2c5f6596e7200e7e1f3bff542fc4339 to your computer and use it in GitHub Desktop.
Sum all number from 0 to X
// 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