Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Boolean Algebra by vvm70
import assert from "assert";
function boolean(x, y, action) {
switch(action) {
case 'conjunction':
return x && y;
case 'disjunction':
return x || y;
case 'implication':
return !x || y;
case 'exclusive':
return x ^ y;
case 'equivalence':
return !(x ^ y);
}
}
console.log('Example:');
console.log(boolean(0, 0, 'conjunction'));
// These "asserts" are used for self-checking
assert.equal(boolean(0, 0, 'conjunction'), 0);
assert.equal(boolean(0, 1, 'conjunction'), 0);
assert.equal(boolean(1, 0, 'conjunction'), 0);
assert.equal(boolean(1, 1, 'conjunction'), 1);
assert.equal(boolean(0, 0, 'disjunction'), 0);
assert.equal(boolean(0, 1, 'disjunction'), 1);
assert.equal(boolean(1, 0, 'disjunction'), 1);
assert.equal(boolean(1, 1, 'disjunction'), 1);
console.log("Coding complete? Click 'Check' to earn cool rewards!");
Oct. 19, 2020