Skip to content

Instantly share code, notes, and snippets.

@shawndumas
Created August 8, 2011 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shawndumas/1131706 to your computer and use it in GitHub Desktop.
Save shawndumas/1131706 to your computer and use it in GitHub Desktop.
Starting with NAND only...
var logicGates = {
nand: function (a, b) {
return !(a && b);
},
not: function (a) {
return this.nand(a, a);
},
and: function (a, b) {
return this.not(this.nand(a, b));
},
or: function (a, b) {
return this.nand(this.not(a), this.not(b));
},
nor: function (a, b) {
return this.not(this.or(a, b));
},
xor: function (a, b) {
return this.and(this.nand(a, b), this.or(a, b));
},
xnor: function (a, b) {
return this.not(this.xor(a, b));
}
};
[
{a: false, b: false},
{a: false, b: true},
{a: true, b: false},
{a: true, b: true},
].map(function (x) { return logicGates.nand(x.a, x.b); });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment