Skip to content

Commit

Permalink
Cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
w3nl committed Jun 25, 2020
1 parent 0a01c70 commit 401f166
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 50 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.1",
"version": "1.0.2",
"description": "",
"main": "src/TruthTable.mjs",
"files": [
Expand Down
56 changes: 8 additions & 48 deletions src/TruthTable.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,75 +26,35 @@ class TruthTable {
}

get and() {
const result = [];
this.inputs.forEach(row => {
result.push(row.every(Boolean));
});

return result;
return this.inputs.map(row => row.every(Boolean));
}

get nand() {
const result = [];
this.inputs.forEach(row => {
result.push(!row.every(Boolean));
});

return result;
return this.inputs.map(row => !row.every(Boolean));
}

get or() {
const result = [];
this.inputs.forEach(row => {
result.push(row.some(Boolean));
});

return result;
return this.inputs.map(row => row.some(Boolean));
}

get nor() {
const result = [];
this.inputs.forEach(row => {
result.push(!row.some(Boolean));
});

return result;
return this.inputs.map(row => !row.some(Boolean));
}

get andWithInputs() {
const result = [];
this.inputs.forEach(row => {
result.push([row.every(Boolean), ...row]);
});

return result;
return this.inputs.map(row => [row.every(Boolean), ...row]);
}

get orWithInputs() {
const result = [];
this.inputs.forEach(row => {
result.push([row.some(Boolean), ...row]);
});

return result;
return this.inputs.map(row => [row.some(Boolean), ...row]);
}

get nandWithInputs() {
const result = [];
this.inputs.forEach(row => {
result.push([!row.every(Boolean), ...row]);
});

return result;
return this.inputs.map(row => [!row.every(Boolean), ...row]);
}

get norWithInputs() {
const result = [];
this.inputs.forEach(row => {
result.push([!row.some(Boolean), ...row]);
});

return result;
return this.inputs.map(row => [!row.some(Boolean), ...row]);
}

static create(propositions) {
Expand Down

0 comments on commit 401f166

Please sign in to comment.