Created
March 4, 2021 16:21
-
-
Save alexcrist/e64946795001a3f1ed0c75455f441d2f to your computer and use it in GitHub Desktop.
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
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