Skip to content

Instantly share code, notes, and snippets.

@alexcrist
Created March 4, 2021 16:21
Show Gist options
  • Save alexcrist/e64946795001a3f1ed0c75455f441d2f to your computer and use it in GitHub Desktop.
Save alexcrist/e64946795001a3f1ed0c75455f441d2f to your computer and use it in GitHub Desktop.
function getSum(a, b) {
// Determine which number is smaller and bigger
let smallest = a;
let biggest = b;
if (b < a) {
smallest = b;
biggest = a;
}
// Sum all the numbers between them (inclusive)
let sum = 0;
for (let i = smallest; i <= biggest; i++) {
sum = sum + i;
}
return sum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment