JavaScript

recurSum(n) { if (n > 0) // do nothing if n is less than 1 { if(n == 1) console.log(1); else // only recurse if n is greater than 1 console.log(n + recurSum(n - 1)); } }

[edit]

The above code has a simple flaw. The following is the correct implementation:

JavaScript

function recurSum(n) { if (n > 0) { // do nothing if n is less than 1 if (n == 1) { return 1; // console.log(1); } else { // only recurse if n is greater than 1 return n + recurSum(n - 1); } } }

[/edit]