cm0002@lemmy.world to Programmer Humor@programming.dev · 2 days agoInfallible Codefeddit.ukimagemessage-square57fedilinkarrow-up1284arrow-down118
arrow-up1266arrow-down1imageInfallible Codefeddit.ukcm0002@lemmy.world to Programmer Humor@programming.dev · 2 days agomessage-square57fedilink
minus-squareEbber@lemmings.worldlinkfedilinkarrow-up13·2 days agoI removed the tail recursion for you: private book IsEven(int number) { if(number > 1) return IsEven(number - 2) == true; if(number == 0) return true; if(number == 2) return false; }
minus-squareFerk@programming.devlinkfedilinkarrow-up3·14 hours agoWhat’d be the result for IsEven(1)?
minus-squareulterno@programming.devlinkfedilinkEnglisharrow-up3·2 days agoI didn’t get this. Why return book? Does that have some Blizzard reference? And why would number == 2 ⇒ return false? This is a function for getting true when the number is even, right?
minus-squareEbber@lemmings.worldlinkfedilinkarrow-up12·edit-22 days agoHaha, you’re right. I’ve now learned two things: I should not write code on a mobile I should not become a proof reader At the end of the day i just wanted the function to be worse, by causing stack overflows
I removed the tail recursion for you:
private book IsEven(int number) { if(number > 1) return IsEven(number - 2) == true; if(number == 0) return true; if(number == 2) return false; }
What’d be the result for
IsEven(1)
?Stack overflow
I didn’t get this.
Why return
book
? Does that have some Blizzard reference?And why would
number == 2
⇒return false
? This is a function for gettingtrue
when the number is even, right?Haha, you’re right. I’ve now learned two things:
At the end of the day i just wanted the function to be worse, by causing stack overflows