- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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
- Related Articles
- Implementation of Boolean Functions using Logic Gates
- Basic Logic Gates – Definition, Types, Boolean Function, and Truth Table
- JavaScript -Short-circuiting in boolean
- Explain non-boolean value coercion to a boolean one in JavaScript?
- Logic Gates in Python
- JavaScript Boolean constructor Property
- Walls and Gates in C++
- JavaScript's Boolean function?
- How [ ] is converted to Boolean in JavaScript?
- How to declare boolean variables in JavaScript?
- How to declare a boolean in JavaScript?
- What is Logic Gates?
- JavaScript Convert a string to boolean
- How null is converted to Boolean in JavaScript?
- How is NaN converted to Boolean in JavaScript?

Advertisements