Skip to content

Commit

Permalink
Merge a607564 into 2cc0ed0
Browse files Browse the repository at this point in the history
  • Loading branch information
w3nl committed Jun 25, 2020
2 parents 2cc0ed0 + a607564 commit 694b194
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hckrnews/truth-table",
"version": "1.0.2",
"version": "1.0.3",
"description": "",
"main": "src/TruthTable.mjs",
"files": [
Expand Down
24 changes: 13 additions & 11 deletions src/TruthTable.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@ class TruthTable {
}

generate() {
for (let index = 0; index < this.combinations; index += 1) {
const binary = parseInt(index, 10)
.toString(2)
.padStart(this.propositions, '0');
this.addRow(binary, index);
}
const inputs = Array(this.combinations).fill(false);

this.inputs = inputs.map((value, index) => this.addRow(index));
}

dec2bin(number) {
return parseInt(number, 10)
.toString(2)
.padStart(this.propositions, '0');
}

addRow(string, col) {
this.inputs.push([]);
addRow(row) {
const binary = this.dec2bin(row);
const inputs = Array(this.propositions).fill(false);

for (let index = 0; index < this.propositions; index += 1) {
this.inputs[col].push(string.substr(index, 1) === '1');
}
return inputs.map((value, index) => binary.substr(index, 1) === '1');
}

get and() {
Expand Down

0 comments on commit 694b194

Please sign in to comment.