In TypeScript, is there a way we can create a generalized function to execute OR operation for any number of arguments passed?
I can write a function for 2 arguments. The requirement is to generalize this for any number of arguments.
export const performOR = (arg1, arg2) => arg1 || arg2;
const isArg1OrArg2 = performOR(x, y);
If this can be achieved by passing an array of arguments, that’s also fine.
>Solution :
This sounds like homework, but:
export const performOR = (...args: any[]):boolean => {
for(const item of args) {
if (item) return true;
}
return false;
}