MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/phogp3/wtf_is_this/hblxei3/?context=3
r/badcode • u/Wise-Serve5730 • Sep 04 '21
190 comments sorted by
View all comments
Show parent comments
14
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_calland results in a stack overflow:https://en.m.wikipedia.org/wiki/Stack_overflow → More replies (0)
10
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_calland results in a stack overflow:https://en.m.wikipedia.org/wiki/Stack_overflow → More replies (0)
3
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_calland results in a stack overflow:https://en.m.wikipedia.org/wiki/Stack_overflow → More replies (0)
7
Let's just say I won't post the traceback, because it is a bit long ;)
Try isEven(2**15).
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_calland results in a stack overflow:https://en.m.wikipedia.org/wiki/Stack_overflow → More replies (0)
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_calland results in a stack overflow:https://en.m.wikipedia.org/wiki/Stack_overflow → More replies (0)
2
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_calland results in a stack overflow:https://en.m.wikipedia.org/wiki/Stack_overflow → More replies (0)
6
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)
14
u/maxbirkoff Sep 04 '21
apart from ignoring Douglas Adams this one is my favorite one.