isEven: Overly Complicated vs Simplified

Two implementations with identical behavior. Try any integer in the live demo.

Overly Complicated

function isEvenOverlyComplicated(n) {
  // Needlessly recursive loop instead of modulo
  const abs = Math.abs(n);
  const helper = (num, state) => {
    if (num === 0) return state === 'even';
    if (num === 1) return state === 'odd';
    return helper(num - 2, state);
  };
  return helper(abs, abs % 4 === 0 || abs % 4 === 2 ? 'even' : 'odd');
}

Simplified

function isEvenSimplified(n) {
  // Identical behavior, obvious modulo check
  return n % 2 === 0;
}
Overly Complicated
Simplified

Try these preset numbers

Verification Table

At least 5 numbers proving identical behavior.

Input Overly Complicated Simplified Match?