开发者

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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜