search a big value on an array

search a big value on an array

Postby Silvio.Falconi » Wed Nov 18, 2020 11:31 am

If I have this array

aData:= { {"B", 0.2, 0.1 ,3.6 ,0.7},;
{"T", 0.2, 0.75 ,3.6 ,0.5},;
{"T", 0.2, 1.2 ,3.6 ,0.4},;
{"T", 0.2, 1.6 ,3.8 ,0.4},;
{"T", 0.2, 1.6 ,3.6 ,0.4},;
{"T", 0.2, 1.6 ,3.6 ,0.4} }


I would like to find the largest number of the 4th array column ( adata[n][4])

how I must make ?
thanks

I made

nHeightold:= adata[1][4]

For n= 1 to Len(adata)
If adata[n][4]>nHeightold
nHeightBig:= adata[n][4]
nHeightold:= adata[n][4]
Endif


next

but I believe there is a better method
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7033
Joined: Thu Oct 18, 2012 7:17 pm

Re: search a big value on an array

Postby driessen » Wed Nov 18, 2020 10:24 pm

Silvio,

Why don't you sort the array first

aData := ASort(aData,,,{|x,y| (x[4]>y[4]})

The largest number is in adata[1,4].
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: search a big value on an array

Postby FranciscoA » Fri Nov 20, 2020 8:24 pm

local nValMayor := 0, nCol := 4
AEval( aData, {|a| if( a[nCol] > nValMayor, (nValMayor := a[nCol], ) } )
Francisco J. Alegría P.
Chinandega, Nicaragua.

Fwxh-MySql-TMySql
User avatar
FranciscoA
 
Posts: 2158
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 21 guests