I have the following:
var cond1 = (a>b) ? true: false;
var cond2 = (d<c) ? true: false;
var cond3 = (e==f) ? true: false;
var found = cond1 && cond2 && cond3;
I want to be able in an elegant way to substitute the && logical operator for another like || and do this programmatically, as in a sort of "variable" operator. Because I don't want to do something like:
var found1 = cond1 && cond2 && cond3;
var found2 = cond1 || cond2 || cond3;
var found3 = (cond1 && cond2) || cond3;
and then switch/if depending on what choice the user has selected from the interface, it's not elegant.
How can I do this ? (if possible)
Thank you in advance
var cond1 = a > b;and finally||is as much operator as&&is, substitute one for another definatelly does not make your code more elegant.CheckConditionsthat takes operators as parameters and compares cond1,2,3? So your found variables could befound1 = CheckConditions('&&', '&&')?var cond1 = a > bwill give exactly the same result asvar cond1 = a > b ? true : false. the result of expressiona>bis alreadytrueorfalse.