Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.28 KB | None | 0 0
  1. const xor = (a, b) => Boolean(a) !== Boolean(b);
  2. const and = (a, b) => Boolean(a) && Boolean(b);
  3.  
  4. const toBit = predicate => (a, b) => (predicate(a, b) ? 1 : 0);
  5. const xorBit = toBit(xor);
  6. const andBit = toBit(and);
  7.  
  8. const halfAdder = (a, b) => ({ c: andBit(a, b), s: xorBit(a, b) });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement