Created
November 20, 2018 20:16
-
-
Save tuvo1106/1e86fabf7495e4633b1b8e85acb95396 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 addWithRecursion = x => { | |
// base case | |
return x <= 0 | |
// ends function when x hits 0 | |
? 0 | |
// checks if x divides evenly by 2 | |
: x % 2 === 0 | |
// retains x and adds it to the function call of x - 1 | |
? x + addWithRecursion(x - 1) | |
// ignores x and moves on to the function call of x - 1 | |
: addWithRecursion(x - 1) | |
} | |
console.log(addWithRecursion(100)) // 2550 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment