pass < or > operator into function as parameter?
actionscript-3, operators, parameters
Solution
Instead of passing an operator, which is impossible in AS3, why not pass a custom comparison function?
function actualFunction(passedValue:Number, compareFunction:Function) {
/* ... */
if(compareFunction(passedValue, staticValue)) {
/* ... Do something ... */
}
/* ... */
}
Then to use it:
actualFunction(6, function(x:Number, y:Number) {
return x > y;
});
or:
actualFunction(6, function(x:Number, y:Number) {
return x < y;
});
Problem
Inside my function there is an `if()` statement like this: ``` if(passedValue < staticValue) ``` But I need to be able to pass a parameter dictating whether the if expression is like above or is: ``` if(passedValue > staticValue) ``` But I cant really pass `<` or `>` operator in has a parameter, so I was wondering what is the best way to do this? Also if the language I am using matters its ActionScript 3.0 Thanks!!