Apologies for the malformed title, I can't really think of a better way to describe what I mean to say. Here is my current code:
fromEn = true; // some boolean value
options = {
from: fromEn ? "en" : "es",
to: fromEn ? "es" : "en"
};
I want from
to be "en"
when fromEn
is true and "es"
when it's false. to
should be the "opposite value" of from
, so-to-speak. I feel my current code is too redundant, and although it works I'd like a more elegant solution. Is there a better way of achieving what I'm trying to do?
EDIT: I decided that ternaries are the best way to go. See Emissary's solution for what I've chosen to do, and see my answer lower to find three possible solutions. Thank you all for the help!