How to perform one binary operation on a binary array?

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

Is there a way to get ANDor the ORwhole array in one way?

+4
source share
3 answers

You can use Booleanas a callback for

var array = [true, true, false];

console.log(array.some(Boolean));  // or
console.log(array.every(Boolean)); // and
Run codeHide result
+3
source

Yes: for ANDyou use arr.every(bool => bool), for ORyou use arr.some(bool => bool).

+2
source

You can use every()for AND:

arr.every(x => x);

And some()for OR:

arr.some(x => x);
+2
source

Source: https://habr.com/ru/post/1687795/


All Articles