UNPKG

@jaimermxd/logic-gates

Version:

A simple package introducing logic gates

31 lines (30 loc) 1.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.not = exports.NotGate = void 0; const BaseGate_1 = require("./BaseGate"); const InvalidInputError_1 = require("../utils/InvalidInputError"); const product_1 = require("../utils/product"); class NotGate extends BaseGate_1.BaseGate { setOutput() { this.output = this.input.map(inp => !inp); } setTruthTable() { this.truthTable.forEach((row, index) => this.truthTable[index].push([...row].map(inp => !inp))); } static getTruthTable(inputs = 1) { if (inputs < 1) throw new InvalidInputError_1.default("'inputs' must be greater than or equal to 1"); let table = product_1.default([false, true], inputs); table.forEach((row, index) => table[index].push([...row].map(inp => !inp))); return table; } checkInputValidity(input) { if (input.length < 1) throw new InvalidInputError_1.default("'input' must contain at least one value"); } } exports.NotGate = NotGate; function not(input) { return NotGate.create(input).output; } exports.not = not;