Created
September 24, 2019 15:07
-
-
Save johnhutchins/0c3742d3b891837bbb16793963815bd9 to your computer and use it in GitHub Desktop.
recursion: find if number is even
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
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