This will give you the highest val without having to loop over the array:

var arr = new Array(6)
arr[0] = "10"
arr[1] = "5"
arr[2] = "40"
arr[3] = "25"
arr[4] = "1000"
arr[5] = "1"
arr[6] = "1001"

var largest = arr.sort(function(a,b){return a - b}).slice(-1)

-----Original Message-----
From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Josh Nathanson
Sent: Wednesday, October 24, 2007 1:36 PM
To: jquery-en@googlegroups.com
Subject: [jQuery] Re: help - compare 3 lists, get the largest number of
items...


You will want $("#myList").size().

Create an array with the three sizes - like var mylistsizes = [ 3, 9, 7 ].

Then, loop over the array and set a variable to the current value.  On each
iteration, if the current iteration is greater than the held variable, reset
the variable to the current iteration.

When the loop is done, your variable will contain the largest value.

-- Josh


----- Original Message -----
From: "rolfsf" <[EMAIL PROTECTED]>
To: <jquery-en@googlegroups.com>
Sent: Wednesday, October 24, 2007 11:25 AM
Subject: [jQuery] help - compare 3 lists, get the largest number of items...


>
>
> I'm still learning the most basic javascript :-(
>
> I have 3 lists. I want to know how many items are in the longest list (ie.
> most <li>). Then, I want to multiply that number by 275
>
> assuming <ul id="myList1" class="myList"> etc.
>
> I know I can get the length of a list using $('#myList').length();
>
> How do I compare 3 numbers and take the largest?
>
> thanks for any help!
>
> Rolf
> -- 
> View this message in context: 
>
http://www.nabble.com/help---compare-3-lists%2C-get-the-largest-number-of-it
ems...-tf4685230s27240.html#a13388830
> Sent from the jQuery General Discussion mailing list archive at 
> Nabble.com.
> 


Reply via email to