I definitely still have a misunderstanding in exercise 2 the recursive isEven function.
So after a few days I got fed up and looked up the solution. Given this solution:
function isEven(n) {
if (n == 0) return true;
else if (n == 1) return false;
else if (n < 0) return isEven(-n);
else return isEven(n - 2);
}
What I am confused about is the last line of code (else return isEven(n-2);). The confusion lies in the call stack computations of n values. If I input 40, what does this line of code do with 40 to return a value of true? I suppose the n-2 condition is what I’m most confused about. Can anyone help explain what happens? Please and thank you !