This is a discussion on "determine which variable has the highest value..." within the Flash & Multimedia Forum section. This forum, and the thread "determine which variable has the highest value... are both part of the Design Your Website category.
|
|
|
|
|
![]() |
||
determine which variable has the highest value...
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
determine which variable has the highest value...
Say I have 8 different variables. Is there an easy code to determine which variable has the highest value without writing a ton of if...then statements?
i.e. var myVariable1 = 23 var myVariable2 = 20 var myVariable3 = 40 var myVariable4 = 22 if (myVariable1 > myVariable2) { if (myVariable1 > myVariable3) { if (myVariable1 > myVariable4) { myVariable1 = theHighestValue; } else { if (myVariable4 > myVariable2) { if(myVariable4 > myVariable3) { myVariable4 = theHighestValue; } else { if (myVariable3 >... i think you get the idea. I'd imagine this problem can be tackled in this tedious manner, but I would also think there is a much easier way to determine this. Can I store the variables in an array and have it sort out which variable in the array has the highest value? |
|
|
|
|||
|
Re: determine which variable has the highest value...
Amazing, a little research and the solution reveals itself:
var myVar1 = 50; var myVar2 = 25; var myVar3 = 100; var myVar4 = 12; var myArray = [myVar1,myVar2,myVar3,myVar4]; trace(myArray);//output = 50,25,75,12 myArray.sort(); trace(myArray); // output: 100,12,25,50 myArray.sort(Array.NUMERIC); trace(myArray); // output: 12,25,50,100 theHighestVariable = myArray[3]; Flash is awesome. |
![]() |
| Tags |
| arrays, conundrum, fuxxor, then, variables |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| What can I use to make something update automatically (people with the highest scores | imagehorizons | PHP Forum | 1 | May 18th, 2008 16:16 |
| Help please : Can't get the highest number to be recognised | madmaxusm | JavaScript Forum | 0 | May 28th, 2007 09:16 |
| Highest Values | robukni | PHP Forum | 6 | May 4th, 2007 11:33 |
| How I determine how much bandwidth I will need? | pengyou | Introduce Yourself | 2 | Sep 10th, 2005 15:55 |
| [SOLVED] Using variables to determine where library items will appear | Anonymous User | Flash & Multimedia Forum | 1 | Feb 9th, 2005 14:30 |