How to get first and second highest totals in a simple way?

Hello,

I have got the totals like

Total1 = 10

Total2 = 20

Total3 = 5

Total4 = 10

Total5 = 15

Total6 = 5

Using the script how can evaluate which is the first highest number and the second highest number?

I would like to get only two numbers.

In this case I would like to get only Total2(first highest) and the Total5(second highest.)

Can someone help me?

Thanks

sri

Subject: How to get first and second highest totals in a simple way?

Hello,

I am not sure in which script (javascript or lotusscript) you are expecting the solution. but i hope the following steps give an idea…

  1. First take all the values in array.

  2. Remove duplicates

  3. Sort the array with remaining values

  4. you can pick first and second highest values with the index.

Thanks,

Sreedhar

Subject: RE: How to get first and second highest totals in a simple way?

use max & min function to get the highest and least values

Subject: RE: How to get first and second highest totals in a simple way?

Hi Sridhar,

Thanks for the response. i am using lotusscript.

Sri

Subject: RE: How to get first and second highest totals in a simple way?

Hello,

Here is the code which satisfies your requirements…must say thanks to Richards as half of the code from his post.

Dim srcList(1 To 10) As Integer	

Dim destList As Variant	



srcList(1)=10

srcList(2)=20

srcList(3)=5

srcList(4)=10

srcList(5)=15

srcList(6)=5



destList=Arrayunique(srcList)		



V1 = -999

V2 = -999



Forall x In destList	

	If x > V1 Then 

		V2 = V1

		V1 = x

	Elseif  x > V2 Then

		V2 = x

	End If

End Forall

Msgbox v1

Msgbox v2

Thanks

Sreedhar

Subject: RE: How to get first and second highest totals in a simple way?

There’s no need to sort the values. It would be quicker to do a one-pass evaluation of the elements.

Something like …

V1 = -999

V2 = -999

For all x in values-to-be-examined

if x > V1 then

V2 = V1

V1 = x

else if x > V2

V2 = x

end if

Next x

V1 will have the largest value, and V2 will have the next largest. If you want to ignore duplicates, then you’ll need additional tests.

Subject: RE: How to get first and second highest totals in a simple way?

Hi richard,

Thanks for the post. here you are comparing only two values. I need to compare 8 values and get the first and second largest values?

How can i do this? please let me know.

Thanks

sri

Subject: RE: How to get first and second highest totals in a simple way?

Look again. He’s suggesting a one-pass loop through all your values.