Pregunta

Let us have 3 variables of type boolean - a, b, c. You can choose the values of these values to be whatever you like (TRUE or FALSE).

Is it possible to create an expression using the three values only once and using only && (AND) operator, || (OR) operator and brackets to make it give us a different result if the brackets were removed.

For example:

var a = false;
var b = false;
var c = false;
var d = true;
console.log(  a || b && c || d  );
console.log(  (a || b) && (c || d)  );

will give us different results because of the brackets.

Is it possible to find an expression using only three variables? I'm using JavaScript but the question is also valid for C, Java, etc...

¿Fue útil?

Solución

It's definitely possible. For example:

var a = true;
var b = false;
var c = false;

console.log(a || b && c);
console.log((a || b) && c);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top