Guest User

Untitled

a guest
Nov 20th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. const addWithRecursion = x => {
  2. // base case
  3. return x <= 0
  4. // ends function when x hits 0
  5. ? 0
  6. // checks if x divides evenly by 2
  7. : x % 2 === 0
  8. // retains x and adds it to the function call of x - 1
  9. ? x + addWithRecursion(x - 1)
  10. // ignores x and moves on to the function call of x - 1
  11. : addWithRecursion(x - 1)
  12. }
  13.  
  14. console.log(addWithRecursion(100)) // 2550
Add Comment
Please, Sign In to add comment