Question: I need to design a global boolean with 2 conditions a and b such that if A is ever true, the boolean is true until b is true, at which point the boolean is false. In other words, if A becomes false the boolean remains true.

I tried a straightforward global variable but it became false when A became false.

Preferably JavaScript, but pseudocode would be almost as helpful.

Answer: 
This sounds like an XOR. i.e. 

```
!A and !B == false
A and !B == true
!A and B == true
A and B == false

```

Unfortunately, JavaScript doesn't have a logical XOR operator, however

if( A ? !B : B ) {

is functionally equivalent
Based on some assumptions about how B should behave if A has not been true:

```
function FlipFlop(){
    this.latch = false;
    this.value = false;
}

FlipFlop.prototype = {
    constructor: FlipFlop,

    setA: function( val ) {
        this.latch = this.latch || !!val;
        this.value = this.latch;
    },

    setB: function( val ) {
        if(this.latch && !!val) {
            this.latch = false;
        }
        this.value = !val;
    },

    getVal: function() {
        return this.value;
    }
}

```