Skip to content

Instantly share code, notes, and snippets.

@johnhutchins
Created September 24, 2019 15:07
Show Gist options
  • Save johnhutchins/0c3742d3b891837bbb16793963815bd9 to your computer and use it in GitHub Desktop.
Save johnhutchins/0c3742d3b891837bbb16793963815bd9 to your computer and use it in GitHub Desktop.
recursion: find if number is even
function isEven(i){
function subtract(){
console.log(i - 2);
return i - 2;
}
if(i===0){ return true; }
if(i === 1){ return false; }
if(i <=0){
return i;
}
return isEven(subtract());
}
//console.log(isEven(-1));
// → true
//console.log(isEven(75));
// → false
//console.log(isEven(-10));
// → ??
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment