-
[CS4] Find biggest variable?
How could i find the biggest variable out of lots of them
i have a few variables and a finalvar
name1
name2
name3
name4
finalvar
each has a value (differs)
what i want is to get the biggest
EG
name1 = 10
name2 = 33
name3 = 21
name4 = 100
finalvar = name4
i would want name 4 (the biggest) to become the value of finalvar
how would i do this :S
TYVM for help
-
Since I'm not trying this out in Flash, you may have to play around with the code a little bit to make sure I used the right syntax, but this should do it for you.
ps. You can add the numbers to the array in any way you want... in fact, you could just add them WITHOUT using variables.... just .push() the number onto the array instead of storing it in a variable.
PHP Code:
var name1:Number = 10; var name2:Number = 33; var name3:Number = 21; var name4:Number = 100;
var myArray:Array = new Array(); myArray.push(name1); myArray.push(name2); myArray.push(name3); myArray.push(name4);
myArray.sort(Array.NUMERIC); //Array.NUMERIC is important because arrays, by default, sort as if all of their values were strings. myArray.reverse();
trace(myArray[0]); //output: 100;
Basically, you're just putting the numbers in an array and sorting them... that puts them in Ascending order, so you'd have to find the LAST number. Instead, you just reverse the array and the largest number will always be at [0].
Last edited by Taidaishar; 10-10-2008 at 03:40 PM.
-
tyvm
i had to mod it a little but it worked
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|