Created
June 22, 2015 09:20
-
-
Save bogdanmoisin/30c3a65fc7f59d70bb40 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
//isEven recursive | |
function isEven( x ) { | |
if ( x == 0 ) { | |
return true; | |
} | |
else if ( x == 1) { | |
return false; | |
} | |
else if ( x < 0 ) { | |
return isEven (-x); | |
} | |
else { | |
return isEven ( x - 2); | |
} | |
} | |
console.log(isEven(50)); | |
// → true | |
console.log(isEven(75)); | |
// → false | |
console.log(isEven(-1)); | |
// → ?? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment