Proyb2
Proyb2

Reputation: 993

Compare between values

With 5 variables consist of a value, I would need to check if any value between fa to fe has a gap of 6 in integer as in f1=1, f2=0, f3=0, f4=7, f5=10; and between f1 and f4, which has a gap of 6.

var f1:int
var f2:int
var f3:int
var f4:int
var f5:int

How do I make the actionscript easier to compare?

Upvotes: 0

Views: 285

Answers (1)

cHao
cHao

Reputation: 86525

Looks like you could do something like

var f:Array = new Array(f1, f2, f3, f4, f5);
f.sort();
for (var x = 0; x < f.length - 1; ++x)
{
    if (f[x+1] - f[x] >= 6)
    {
        // here's your gap
        Alert.show("Gap between "+f[x].toString()+" and "+f[x+1].toString());
    } 
}

Note, it'll tell you whether there's a gap, and which values are at either end of the gap, but it won't specifically say which variables are involved. And it won't necessarily find the largest gap; it'll just find one that qualifies (as i understand the problem).

Upvotes: 2

Related Questions