determine which variable has the highest value...

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.



Go Back   Webforumz.com > Main Forums > Design Your Website > Flash & Multimedia Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Oct 14th, 2006, 23:20
New Member
Join Date: Sep 2006
Location: chicago
Age: 25
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
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?
Reply With Quote

  #2 (permalink)  
Old Oct 14th, 2006, 23:55
New Member
Join Date: Sep 2006
Location: chicago
Age: 25
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Reply With Quote
  #3 (permalink)  
Old Oct 16th, 2006, 02:33
JacobHaug's Avatar
SuperMember

SuperMember
Join Date: Dec 2005
Location: On Internet
Posts: 4,859
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to JacobHaug Send a message via MSN to JacobHaug
Re: determine which variable has the highest value...

Sorry, I had no ideal what the heck you were trying to accomplish. But I am SO GLAD you solved your problem!!
Reply With Quote
Reply

Tags
arrays, conundrum, fuxxor, then, variables

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT. The time now is 02:08.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43