jroid8@lemmy.world to Programmer Humor@lemmy.ml · 11 months agoknow the features of your languagelemmy.worldimagemessage-square143fedilinkarrow-up1641arrow-down124
arrow-up1617arrow-down1imageknow the features of your languagelemmy.worldjroid8@lemmy.world to Programmer Humor@lemmy.ml · 11 months agomessage-square143fedilink
minus-squarecerement@slrpnk.netlinkfedilinkarrow-up13arrow-down1·edit-211 months agoreturn a and a or b → return a or b correction from @murtaza64
minus-squareKogasa@programming.devlinkfedilinkarrow-up1arrow-down1·11 months agoIt’s probably valid javascript that returns “-1” or the empty string depending on if “b” is undefined or null
minus-squaremurtaza64@programming.devlinkfedilinkarrow-up3·edit-211 months agoYou don’t need the and right? Can’t it just be return a or b This doesn’t work if a is falsy non-null actually
minus-squarecerement@slrpnk.netlinkfedilinkarrow-up1·11 months agoit’s just return a and b or c is the closest Lua has to a ternary operator, but yes, for the above you could shorten it to return a or b (“or returns the first argument if true, otherwise second argument is returned”)
→return a and a or b
return a or b
correction from @murtaza64
Lua. My beloved.
That’s valid Python as well
It’s probably valid javascript that returns “-1” or the empty string depending on if “b” is undefined or null
You don’t need the and right? Can’t it just be
return a or b
This doesn’t work if a is falsy non-null actually
it’s just
return a and b or c
is the closest Lua has to a ternary operator, but yes, for the above you could shorten it toreturn a or b
(“or
returns the first argument if true, otherwise second argument is returned”)