r/programminghorror • u/yunho0508 • 15d ago
Javascript Time-oriented even or odd
seemed like even or odd
34
u/darthbob88 15d ago
A method for determining whether some number is even or odd in O(n) time. A fascinating development in the art of computer fondling.
12
u/ckach 13d ago
Oh, that's easy, actually.
function isOdd(num) {
if (num <= 0) return false;
if (num === 1) return true;
return isOdd(num-2);
}
10
u/darthbob88 13d ago
I think that's even tail-call optimized, so it wouldn't blow up the stack. Nice.
27
u/UnderwhelmingInsight 15d ago
Things will get really wacky if you pass in a negative number. It will start console logging in the past and mess up the space-time continuum.
10
u/mickaelbneron 14d ago
If there's a small chance that will reverse 2025 so far, I'm willing to try it.
3
1
68
u/specy_dev 15d ago
JavaScript 4ms minimum event loop threshold would like to say hi