Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.29 KB | None | 0 0
  1. function isEven(n) {
  2. if (n == 0)
  3. return true;
  4. else if (n == 1)
  5. return false;
  6. else if (n < 0)
  7. return isEven(-n);
  8. else
  9. return isEven(n-2);
  10. }
  11.  
  12. console.log(isEven(50));
  13. // → true
  14. console.log(isEven(75));
  15. // → false
  16. console.log(isEven(-1));
  17. // → ?? runs out of stack space -> false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement