function getOddness(n: number):
return (n % 2 === 0)
? "Even"
: "Odd";
Lowest boilerplate makes it the most readable. If working in a language with the ternary operator it ought to be easily recognized! function getOddness(n: number):
return (n % 2 === 0)
? "Even"
: "Odd";
Lowest boilerplate makes it the most readable. If working in a language with the ternary operator it ought to be easily recognized! def oddness(n):
return ["Even", "Odd"][n % 2]
BTW this trick with replacing if-then-else with a lookup is sometimes very useful. Especially if there's many ifs. const getOddness = (n) => (
n % 2
? 'Odd'
: 'Even'
)
Even less visual noise const getOddness = n => n % 2 ? 'Odd' : 'Even'Choosing one of world's spoken languages over others seems to be the opposite of inclusive.
To me and my style of coding, there's a difference of intent between the two. A ternary connotes a mere computation, something that should have no side-effects. A conditional connotes a procedure; the arms of the conditional might be expected to have side-effects. (And the case of `if (_) return` or similar are pure control flow guards; they neither compute a value nor perform a procedure as such.)
It's not just about where the symbols go on the screen.