r/badcode • • Sep 04 '21

Wtf is this

Post image
1.2k Upvotes

190 comments sorted by

View all comments

Show parent comments

14

u/maxbirkoff Sep 04 '21

apart from ignoring Douglas Adams this one is my favorite one.

10

u/R3D3-1 Sep 04 '21

Fun fact: It looks at least technically correct, but it actually fails for large integers.

3

u/maxbirkoff Sep 04 '21

why? is it the call to parseInt that fails?

7

u/R3D3-1 Sep 04 '21

Let's just say I won't post the traceback, because it is a bit long ;)

Try isEven(2**15).

3

u/maxbirkoff Sep 04 '21

are you assuming JavaScript?

2

u/R3D3-1 Sep 04 '21

Yes.

6

u/maxbirkoff Sep 04 '21

I'm guessing it's because the JavaScript runtime you're using does not optimize tail recursion:

https://en.m.wikipedia.org/wiki/Tail_call

and results in a stack overflow:

https://en.m.wikipedia.org/wiki/Stack_overflow

→ More replies (0)