actionscript number is between():Boolean
Does Actionscript have a built-in function tha开发者_StackOverflow中文版t accepts a number and can return a Boolean if this number is between 2 numbers.
For example
3 is between 2 and 6 //returns true
5 is between 10 and 20 //returns false
No, but you can easily code one yourself:
public static function isBetween(x : Number, low: Number, high : Number) : Boolean { return ((x>=low)&&(x<=high)); }
So, for your example, isBetween(3,2,6) returns true and isBetween(5,10,20) returns false. That said, simply using the boolean expression ((x>=2)&&(x<=6)) is much more readable than isBetween(x,2,6).
function calls are pretty slow, so I would stay away from this if you can at all avoid it.
It's not that hard to write: if (x > low && x < high)
精彩评论