@jaimermxd/logic-gates
Version:
A simple package introducing logic gates
31 lines (30 loc) • 1.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.nand = exports.NandGate = void 0;
const BaseGate_1 = require("./BaseGate");
const InvalidInputError_1 = require("../utils/InvalidInputError");
const product_1 = require("../utils/product");
class NandGate extends BaseGate_1.BaseGate {
setOutput() {
this.output = !this.input.every(Boolean);
}
setTruthTable() {
this.truthTable.forEach((row, index) => this.truthTable[index].push(!row.every(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.every(Boolean)));
return table;
}
checkInputValidity(input) {
if (input.length < 2)
throw new InvalidInputError_1.default("'input' must contain at least two values");
}
}
exports.NandGate = NandGate;
function nand(input) {
return NandGate.create(input).output;
}
exports.nand = nand;