Quick actions

cmd+k|ctrl+k

Navigation

Languages

xor assoc truth table

Snippet info

Language

JavaScript

Visibility

public

Author

mjg.py3

Created

2017-05-26T13:48:23Z

Updated

2017-05-26T13:48:23Z

const applyMethod = method => (obj, arg) => obj[method](arg);

Array.prototype.collect = function (f) {
  return this
    .map(f)
    .reduce(applyMethod('concat'), []);
};

const bits = [1, 0];

const xor = (a, b) => a === b ? 0 : 1;

const results =
  bits.collect(
    x => bits.collect(
    y => bits.collect(
    z =>
      xor(xor(x, y), z) === xor(x, xor(y, z))
  )));
  
const isTruthy = Boolean;
  
console.log(results.every(isTruthy));
INFO