Created
May 29, 2020 17:43
-
-
Save alex-hladun/a8e19ae4797d1e248352da057a6f09fe to your computer and use it in GitHub Desktop.
Sum from one number to another recursively.
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
const sum = function(fromN, toN) { | |
if (fromN === toN) { | |
return toN; | |
} else { | |
return fromN + sum(fromN + 1, toN); | |
} | |
}; | |
module.exports = sum; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment