▲ 624 ▼ know the features of your language (lemmy.world) submitted 2 years ago by jroid8@lemmy.world to c/programmerhumor@lemmy.ml 145 comments fedilink hide all child comments
[–] cerement@slrpnk.net 12 points 2 years ago* (last edited 2 years ago) (5 children) return a and a or b → return a or b correction from @murtaza64 permalink fedilink source hideshow 5 child comments replies: [–] DmMacniel@feddit.de 5 points 2 years ago (2 children) Lua. My beloved. permalink fedilink source parent hideshow 2 child comments replies: [–] lm7@lemmy.ml 2 points 2 years ago (1 child) That's valid Python as well permalink fedilink source parent hideshow 1 child comment replies: [–] kogasa@programming.dev 0 points 2 years ago It's probably valid javascript that returns "-1" or the empty string depending on if "b" is undefined or null permalink fedilink source parent [–] murtaza64@programming.dev 3 points 2 years ago* (1 child) 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 permalink fedilink source parent hideshow 1 child comment replies: [–] cerement@slrpnk.net 1 point 2 years ago 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 to return a or b (“or returns the first argument if true, otherwise second argument is returned”) permalink fedilink source parent
[–] DmMacniel@feddit.de 5 points 2 years ago (2 children) Lua. My beloved. permalink fedilink source parent hideshow 2 child comments replies: [–] lm7@lemmy.ml 2 points 2 years ago (1 child) That's valid Python as well permalink fedilink source parent hideshow 1 child comment replies: [–] kogasa@programming.dev 0 points 2 years ago It's probably valid javascript that returns "-1" or the empty string depending on if "b" is undefined or null permalink fedilink source parent
[–] lm7@lemmy.ml 2 points 2 years ago (1 child) That's valid Python as well permalink fedilink source parent hideshow 1 child comment replies: [–] kogasa@programming.dev 0 points 2 years ago It's probably valid javascript that returns "-1" or the empty string depending on if "b" is undefined or null permalink fedilink source parent
[–] kogasa@programming.dev 0 points 2 years ago It's probably valid javascript that returns "-1" or the empty string depending on if "b" is undefined or null permalink fedilink source parent
[–] murtaza64@programming.dev 3 points 2 years ago* (1 child) 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 permalink fedilink source parent hideshow 1 child comment replies: [–] cerement@slrpnk.net 1 point 2 years ago 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 to return a or b (“or returns the first argument if true, otherwise second argument is returned”) permalink fedilink source parent
[–] cerement@slrpnk.net 1 point 2 years ago 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 to return a or b (“or returns the first argument if true, otherwise second argument is returned”) permalink fedilink source parent