1, 0 ver
function and(i, j) {
return i & j;
}
function or(i, j) {
return i | j;
}
function nand(i, j) {
return !and(i, j) ? 1 : 0;
}
function nor(i, j) {
return !or(i, j) ? 1: 0;
}
function xor(i, j) {
return i^j;
}
function not(i) {
return !i ? 1 : 0;
}
引数に何でも渡せるのがJSの良い所
and(0, 0)
or(1, 0)
not( xor(0, 0) )
nor( and(1, 1), or(1, 0) )
true, false ver
function and(i, j) {
return !!(i & j);
}
function or(i, j) {
return !!(i | j);
}
function nand(i, j) {
return !and(i, j);
}
function nor(i, j) {
return !or(i, j);
}
function xor(i, j) {
return !!(i^j);
}
function not(i) {
return !i;
}
引数に何でも渡せるのがJSの良い所 大事なことなので二回言いました
and(false, false)
or(true, false)
not( xor(false, false) )
nor( and(true, true), or(true, false) )
ツン, デレ ver
function and(i, j) {
return ((i == 'ツン') && (j == 'ツン')) ? 'ツン' : 'デレ';
}
function or(i, j) {
return ((i == 'ツン') || (j == 'ツン')) ? 'ツン' : 'デレ';
}
function nand(i, j) {
return not(and(i, j));
}
function nor(i, j) {
return not(or(i, j));
}
function xor(i, j) {
return (i != j) ? 'ツン' : 'デレ';
}
function not(i) {
return (i == 'ツン') ? 'デレ' : 'ツン';
}
ツンってtrueでいいのかな?
and('デレ', 'デレ')
or('ツン', 'デレ')
not( xor('デレ', 'デレ') )
nor( and('ツン', 'ツン'), or('ツン', 'デレ') )