Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Boolean Algebra by Elena_Korljukova
import assert from "assert";
function boolean(x: number, y: number, action: string): number {
if (action == 'conjunction') return x&y;
if (action == 'disjunction') return x|y;
if (action == 'implication') return (x^1)|y;
if (action == 'exclusive') return x^y;
if (action == 'equivalence')return x^y^1;
}
console.log('Example:');
console.log(boolean(0, 0, 'conjunction'));
console.log(boolean(0, 0, 'implication'));
// 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. 21, 2020