Asort based on two array elements

Asort based on two array elements

Postby Marco Turco » Thu May 19, 2016 2:21 pm

Hi all,
I need to order the following array by date and by name (inside a date).
Do you have any suggest about ?

* date is the first element, name is the second
aArray:={}
aadd(aArray,{"01/10/2015","Marc"})
aadd(aArray,{"01/10/2015","Alexandra"})
aadd(aArray,{"01/07/2015","Paul"})
aadd(aArray,{"01/04/2015","Alexandra"})
aadd(aArray,{"01/04/2015","Marc"})

Thank you in advance
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Re: Asort based on two array elements

Postby Diego Decandia » Thu May 19, 2016 2:46 pm

Hi Marco,

maybe using a third element?

aadd(aArray,{ "01/10/2015", "Marc", DTOS( CTOD( "01/10/2015" ) ) + "Marc" } )
Diego Decandia
 
Posts: 40
Joined: Fri Aug 22, 2014 6:21 am

Re: Asort based on two array elements

Postby nageswaragunupudi » Thu May 19, 2016 4:07 pm

Code: Select all  Expand view
ASort( aArray, nil, nil, { |x,y| If( x[ 1 ] == y[ 1 ], x[ 2 ] < y[ 2 ], x[ 1 ] < y[ 1 ] ) } )
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Asort based on two array elements

Postby Marco Turco » Sat May 21, 2016 3:44 pm

Solved, thank you Nages
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 95 guests