Skip to content

Instantly share code, notes, and snippets.

@AntonisFK
Created April 22, 2016 23:05
Show Gist options
  • Save AntonisFK/4498407c521dd6070ca960a85b6d22d9 to your computer and use it in GitHub Desktop.
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);
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