Two functions, identical behavior, wildly different approaches.
// Uses needless recursion instead of modulo function isEven(n) { // Base case: zero is even if (n === 0) return true; // Base case: negative one is odd if (n === -1) return false; // Recurse by subtracting 2 if (n > 0) return isEven(n - 2); return isEven(n + 2); }
// The obvious, correct approach function isEven(n) { return n % 2 === 0; }
| Input | Overly Complicated | Simple | Match? |
|---|