This looks like JavaScript. If that is the case and the function is used like this if(or(true, false)) { ... } it will actually work, because an empty string gets converted to false and a non-empty string to true. However "true"==true will return false, so you can't use the output of the or function as an input to it.
It uses “==“, and “true” is truthy value, so “true”==true will return true. Or so I think - I haven’t actually used “==“ in JS since somewhere in 2016 when I just started out.
I thought it works that way, but I actually tested with a nodejs docker container. It does not. 'true == "true"' evaluates to false. The console in firefox also returns false.
I have no idea what is going on there and I will not even try to understand it.
yes you can omit both Boolean() since the if() already does this in JS and also, yes you could omit the last return and if() and return the Boolean(b) directly (which then needs the Boolean() tho too be bool value type) so:
Well as i'm quite experienced with writing algorithms, i of course know that we need to do that with recursion. This also hs the added advantage that this can be written in far fewer lines of code. Hence my code is better:
Function or(a,b): { Var out = or(a,b) Return out }
70
u/someidiot332 Mar 12 '23
What is this even supposed to do? And why not use just || ?
69
u/squeevey Mar 12 '23 edited Oct 25 '23
This comment has been deleted due to failed Reddit leadership.
12
u/Ximidar Mar 12 '23
Cloud Atlas programming. He's just trying to get the true true.
10
u/[deleted] Mar 12 '23
truetrue
9
u/fiddz0r Mar 12 '23
I wonder how the return variable is used in the rest of the code. I imagine it like
6
u/megamaz_ Mar 12 '23
a=true and b=true, out="truetrue"
5
u/Darknety Mar 12 '23
truetrue
3
u/lazyzefiris Mar 13 '23
Why not just
1
u/lofi_reddit Mar 12 '23
truetrue
1
u/shizzy0 Mar 13 '23
Right, right.
1
u/Public-Estate4555 Mar 13 '23
You are missing the else statement!!! /s
1
u/mMykros Mar 13 '23
truetrue
1
u/poope_lord Mar 13 '23
If both are true it returns "truetrue".
1
u/Niilldar Mar 12 '23
Well as i'm quite experienced with writing algorithms, i of course know that we need to do that with recursion. This also hs the added advantage that this can be written in far fewer lines of code. Hence my code is better:
Function or(a,b): { Var out = or(a,b) Return out }
0
u/UndisclosedChaos Mar 12 '23
Me: Guys guys, we can’t just write bad code just to post to this subreddit
OP: I didn’t
Me: D:
0
u/[deleted] Mar 12 '23
The | operator is crying in the corner
0
u/CedricCicada Mar 12 '23
We don't know what the requirements were for this function. Maybe this function does exactly what it was supposed to do.
0
u/Teln0 Mar 13 '23
I mean, it returns a truthy value and a falsy value in the appropriate cases...