I'm trying to make a function to filter some data using OR/AND logical operator depending on what the user selects. That means I need to use Array.prototype.every (AND) or Array.property,some (OR) to fullfill my requirement.
To avoid code redundancy I was trying to do something like this:
const functionApplied = condition === 'ALL'
? myArray.every
: myArray.some;
functionApplied(item => {
... aux code ...
})
functionApplied.call(item => {
... aux code ...
})
Is there an analogous way to do it like this?
I know I could do something like this, but I'm just curious about above sintax...
const auxFunction = (item) => {...};
if (condition === 'ALL') {
myArray.every(item => auxFunction(item));
} else {
myArray.some(item => auxFunction(item));
}
.callusage isfunctionApplied.call(myArray, item => { ... aux code ... })since you need to supply the value forthis.