In C# there are various ways to do this C# Pass bitwise operator as parameter specifically the "Bitwise.Operator.OR" object, but can something like this be done in JavaScript? For example:
function check(num1, num2, op) {
return num1 op num2; //just an example of what the output should be like
}
check(1,2, >); //obviously this is a syntax error, but is there some kind of other object or bitwise operator of some kind I can plug into the place of ">" and change the source function somehow?
eval()
which is not good. – Leytenew Function
is better here. – Spookynew Function
also useseval()
– Leytenum1
andnum2
to, which returns the evaluated expression – Carpometacarpuscond1 ? expr1 : expr2
– Carpometacarpus'?:': (cond, expr1, expr2) => cond ? expr1 : expr2
– Carpometacarpus>
one in their example. – Spookycheck['&&'](check['<'](2, 5), check['<'](8, 10))
etc, something like that – Carpometacarpus