4 ms·
It works for me. Note that `|` is a bitwise-or (not that it really matters, it just removes a branch) const True = -1 const False = 0 const ternary
by repsilat 8y ago
It works for me. Note that `|` is a bitwise-or (not that it really matters, it just removes a branch)
const True = -1
const False = 0
const ternary = (condition, left, right) => \
(condition & left) | (~condition & right)
ternary(True, 0, 1) // 0
ternary(False, 0, 1) // 1
- eridius 8y agoOh right, because the right-hand side evaluates to 0 as well in this case. Makes sense.