Created
August 8, 2011 13:06
-
-
Save shawndumas/1131706 to your computer and use it in GitHub Desktop.
Starting with NAND only...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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