 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Boolean Gates in JavaScript
Problem
We are required to write a JavaScript function that takes in an array of Boolean values and a logical operator.
Our function should return a Boolean result based on sequentially applying the operator to the values in the array.
Example
Following is the code −
const array = [true, true, false]; const op = 'AND'; function logicalCalc(array, op){    var result = array[0];    for(var i = 1; i < array.length; i++){       if(op == "AND"){          result = result && array[i];       }       if(op == "OR"){          result = result || array[i];       }       if(op == "XOR"){          result = result != array[i];       }    }    return result; } console.log(logicalCalc(array, op)); Output
false
Advertisements
 