Skip to content

Instantly share code, notes, and snippets.

@bogdanmoisin
Created June 22, 2015 09:20
Show Gist options
  • Save bogdanmoisin/30c3a65fc7f59d70bb40 to your computer and use it in GitHub Desktop.
Save bogdanmoisin/30c3a65fc7f59d70bb40 to your computer and use it in GitHub Desktop.
//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