Skip to content
Jaime Redondo edited this page Jan 2, 2021 · 2 revisions

@jaimermxd/logic-gates

A simple package introducing logic gates.

Installation

$ npm install @jaimermxd/logic-gates

Usage

const { AndGate, and, not, NotGate } = require("@jaimermxd/logic-gates");

// Basic gate usage

let andGate = AndGate.create([true, false, true, false, false]);
console.log(andGate.input); // [ true, false, true, false, false ]
console.log(andGate.output); // false

let shortAndGate = and([true, true, true]);
console.log(shortAndGate); // true

let shortNotGate = not([false, true, true, true, false, true]);
console.log(shortNotGate); // [ true, false, false, false, true, false ]

// Truth tables

let xorGate = XorGate.create([false, true]);
console.log(xorGate.truthTable); // [ [ false, false, false ], [ false, true, true ], [ true, false, true ], [ true, true, false ] ]

let xorTruthTable = XorGate.getTruthTable(2);
console.log(xorTruthTable); // [ [ false, false, false ], [ false, true, true ], [ true, false, true ], [ true, true, false ] ]

Contributing

Pull requests are welcome. For major changes, open an issue first to discuss what you would like to change.

License

Released under the MIT license.

Clone this wiki locally