Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have one binary operation performed over a binary array?

Suppose a binary array var arr = [true, true, false];.

Is there any way to get the AND or OR of the whole array using one method?

like image 245
amitava mozumder Avatar asked Mar 08 '23 18:03

amitava mozumder


1 Answers

You could use Boolean as callback for

  • OR with Array#some or for

  • AND with Array#every.

var array = [true, true, false];

console.log(array.some(Boolean));  // or
console.log(array.every(Boolean)); // and
like image 163
Nina Scholz Avatar answered Apr 26 '23 18:04

Nina Scholz