Question: I have a function that changes the case of some text and returns it, based on the value of `capitalisation`. I would like to pass another parameter called `inverse`, which if true, basically performs the opposite; so if `capitalisation` is lowercase, it will make the text lower case instead of uppercase.

It's important that the value of `capitalisation` does not change, because it's used by other parts of the application.

I'm looking for a really succinct way to do this with minimal code.

```
       capitalisation = "lowercase";

       function switchCase(text, inverse) {
            if (capitalisation === "lowercase") {
                text = text.toLowerCase();
            } else {
                text = text.toUpperCase();
            }
            return text;
        }

```

Answer: 
In boolean algebra, to invert a logic based on another logical condition you'd use the XOR operator. This is because the truth table is:

```
a       b       result
true    false   true
false   false   false
true    true    false
false   true    true

```

Notice that if we rename b as inverse:

```
a       inverse      result
true    not_inverse  same_as_a
false   not_inverse  same_as_a
true    inverse      opposite_of_a
false   inverse      opposite_of_a

```

So what you want is:

```
if ((capitalisation === "lowercase")  XOR  inverse) ...

```

Unfortunately javascript does not have a logical XOR operator, only a bitwise `^` operator. However, it's easy to implement XOR as `(a && !b) || (!a && b)`. This gives us:

```
if (((capitalisation === "lowercase") && !inverse) ||
    ((capitalisation !== "lowercase") && inverse)) ...

```
if I understand well:

```
    var capitalisation = "lowercase";
    var inverse = false;

   function switchCase(text, inverse) {
        if (capitalisation === "lowercase") {
            text = text.toLowerCase();
        } else {
            text = text.toUpperCase();
        }
        return text;
    }

   function switchCase2(text, inverse) {
        return inverse ? text.toLowerCase() : text.toUpperCase() ;
    }

    alert(switchCase2('GGFGFF',inverse));

```

[Demo](https://jsfiddle.net/xg3arot8/)