Skip to content

Instantly share code, notes, and snippets.

@jonurry
Last active April 28, 2021 03:01
Show Gist options
  • Save jonurry/95ce2b5e98a2c9cfb44b13da37aa2105 to your computer and use it in GitHub Desktop.
Save jonurry/95ce2b5e98a2c9cfb44b13da37aa2105 to your computer and use it in GitHub Desktop.
3.2 Recursion (Eloquent JavaScript Solutions)
function isEven(num) {
if (num == 0)
return true;
if (num == 1)
return false;
if (num < 0)
return "??";
else return isEven(num - 2);
}
console.log(isEven(50));
// → true
console.log(isEven(75));
// → false
console.log(isEven(-1));
// → ??
@Angstromico
Copy link

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment