Couldn't really find an answer for this.
I have a function which should allow users to pass it "checks" (functions that returns true or false). The checks will run on a large number of items. For each item I want to know if all the checks returned true.
function foo(checksArray) { //checksArray: [func1, func2, func3]
var itemList = [1, 2, 3, 4];
for (item of itemList)
if (checkAllFunctions(item))
doSomething();
}
How can I do it? Obviously I can iterate over each function with a for loop but I suspect there might be a better way. Maybe there's even a one-liner.
Thanks for any help guys.
Edit: I guess there isn't really any point in keeping running even though one of checks returned false. If it can stop right there, that's even better!
foobomb out as soon as possible?doSomethingmethodsyncorasync?Array.prototype.everyorArray.prototype.somesync. @Andreas I'll check them, thanks!Array.prototype.every. Something like thisitemList.every( item => checksArray.every(check => check(item)))