UNPKG

@jaimermxd/logic-gates

Version:

A simple package introducing logic gates

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