-3

Is there a way to simplify the below logic to use less than 5 operators (&& / ||) without creating new variables?

var foo = (A || B) && C && [(A && D) || (B && E)]
Manish Poduval
  • 452
  • 3
  • 15

1 Answers1

1

Assuming [] means (), then you could drop some parenthesis, because of the operator precedence of && (6) over || (5).

var foo = (A || B) && C && (A && D || B && E);

Then you could drop the first part, because of the condition in the last part,

var foo = (A || B) && C && (A && D || B && E);
//         ^    ^           ^         ^     

because not only A has to be true as well as D or B has to be true and E as well.

var foo = C && (A && D || B && E);
Nina Scholz
  • 376,160
  • 25
  • 347
  • 392