https://github.com/multarix/truthtable
Makes truth tables
https://github.com/multarix/truthtable
Last synced: 11 months ago
JSON representation
Makes truth tables
- Host: GitHub
- URL: https://github.com/multarix/truthtable
- Owner: Multarix
- License: mit
- Created: 2022-04-01T10:06:06.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2023-07-22T12:18:56.000Z (over 2 years ago)
- Last Synced: 2025-01-12T17:36:42.692Z (about 1 year ago)
- Language: TypeScript
- Homepage:
- Size: 42 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Truth Table
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:
- `¬` = `!`
- `∨` = `||`
- `∧` = `&&`
- `↔` = `===`
---
# TruthTable class
## Constructor
Takes a string argument as the first expression, and an array of strings as the second argument for the variables.
## Properties
- `expression` - The expression passed into the constructor.
- `variables` - The variables passed into the constructor.
## Methods
### .createTable()
Returns an array of objects containing the truth table.
Takes no arguments.
---
### .log()
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`.
---
# Example Usage
```js
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
*/
```