Created
April 22, 2016 23:05
-
-
Save AntonisFK/4498407c521dd6070ca960a85b6d22d9 to your computer and use it in GitHub Desktop.
Write a recursive function that given a number returns sum of integers from 1 to that number. Example: rSigma(5) = 15 (1+2+3+4+5);
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 rSigma (num){ | |
if(num === 0){ | |
return num; | |
} else { | |
return num + rSigma(num-1); | |
} | |
} | |
rSigma(5); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment