Suppose a binary array exists var arr = [true, true, false];.
var arr = [true, true, false];
Is there a way to get ANDor the ORwhole array in one way?
AND
OR
You can use Booleanas a callback for
Boolean
OR with Array#someor for
Array#some
And with Array#every.
Array#every
var array = [true, true, false]; console.log(array.some(Boolean)); // or console.log(array.every(Boolean)); // and
Yes: for ANDyou use arr.every(bool => bool), for ORyou use arr.some(bool => bool).
arr.every(bool => bool)
arr.some(bool => bool)
You can use every()for AND:
every()
arr.every(x => x);
And some()for OR:
some()
arr.some(x => x);
Source: https://habr.com/ru/post/1687795/More articles:Playing videos in Safari at an event - javascriptForcing case-insensitive strings. Entity Framework Content - stringReturn a specific value when a list is out of range in Python - pythonPerl is a random string, but does not seem so random when used in a browser - randomUsing start v4 in a retraining example - pythonPHP: How to get CURRENT innerHTML? - javascriptHow to distribute .net core 2.0 console application on osx - .net-coreIOS Image Data Detection - HEIF or HEIC - iosRtools cygheap database inconsistency detected - Windows update - windowsDoes LinkedHashSet constructor keep order - javaAll Articles