Timkor

codeWars

Nov 13th, 2020
753
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function XOR(a, b) {
  2.     return ((!a && b) || (a && !b));
  3. }
  4.  
  5. function AND(a, b) {
  6.     return (a && b);
  7. }
  8.  
  9. function OR(a, b) {
  10.     return (a || b);
  11. }
  12.  
  13. function logicalCalc(array, operator) {
  14.     boolOperators = {
  15.         'AND': AND,
  16.         'OR': OR,
  17.         'XOR': XOR
  18.     }
  19.     let result = array[0];
  20.     for (let i = 1; i < array.length; i++) {
  21.         result = boolOperators[operator](result, array[i])
  22.     }
  23.     return result;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment