Allows for easy truth table building.
Can also convert some of the dumb math jargon like "¬" meaning "not" or "∧" meaning "and" into javascript readable statements.
Currently supported math jargon:
¬
=!
∨
=||
∧
=&&
↔
====
Takes a string argument as the first expression, and an array of strings as the second argument for the variables.
expression
- The expression passed into the constructor.variables
- The variables passed into the constructor.
Returns an array of objects containing the truth table. Takes no arguments.
Logs the truth table to the console.
- Takes a boolean argument, which determines if the console output will be colored or not. Defaults to
false
.
const expression = "((!a && b) || (c && (!b || !d)) && (!c === b))";
const variables = ["a", "b", "c", "d"];
const truthTable = new TruthTable(expression, variables);
truthTable.log(); // Results in the below being outputt to the console:
/*
| a | b | c | d | ((¬a ∧ b) v (c ∧ (¬b v ¬d)) ∧ (¬c ↔ b))
-------------------------------------------------------------------------
| True | True | True | True | -> False
| True | True | True | False | -> False
| True | True | False | True | -> False
| True | True | False | False | -> False
| True | False | True | True | -> True
| True | False | True | False | -> True
| True | False | False | True | -> False
| True | False | False | False | -> False
| False | True | True | True | -> True
| False | True | True | False | -> True
| False | True | False | True | -> True
| False | True | False | False | -> True
| False | False | True | True | -> True
| False | False | True | False | -> True
| False | False | False | True | -> False
| False | False | False | False | -> False
*/