Two implementations with identical behavior. Try any integer in the live demo.
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');
}
function isEvenSimplified(n) {
// Identical behavior, obvious modulo check
return n % 2 === 0;
}
At least 5 numbers proving identical behavior.
| Input | Overly Complicated | Simplified | Match? |
|---|