Hi,
I have an array of CDT ABC:
{
{ Id: 111111, position: L1}
{ Id: 22222, position: R2}
{ Id: 333, position: L2}
{ Id: 44, position: R1}
{ Id: 555, position: L3}
{ Id: 666, position: R3}
}
Now I need to sort this array as
Can someone give me some hint?
Thanks,
Peiran
Discussion posts and replies are publicly visible
Few ways to do this, here is an example that first finds how many L and R values are in the CDT then uses that count to loop each and build a sorted CDT:
a!localVariables( local!cdt: { { Id: 111111, position: "L1"}, { Id: 22222, position: "R2"}, { Id: 333, position: "L2"}, { Id: 44, position: "R1"}, { Id: 555, position: "L3"}, { Id: 666, position: "R3"} }, local!countPositionL: count(where(a!forEach( items: local!cdt.position, expression: if(search("L",fv!item,1)>0,true,false) ))), local!countPositionR: count(where(a!forEach( items: local!cdt.position, expression: if(search("L",fv!item,1)>0,true,false) ))), a!flatten( { a!forEach( items: 1+enumerate(local!countPositionL), expression: index( local!cdt, wherecontains(concat("L",fv!index),a!foreach(items:local!cdt.position, expression: tostring(fv!item))), {} ) ), a!forEach( items: 1+enumerate(local!countPositionR), expression: index( local!cdt, wherecontains(concat("R",fv!index),a!foreach(items:local!cdt.position, expression: tostring(fv!item))), {} ) ) } ) )
Mike Schmitt, Chris,
All your solution are working!
Thanks!
Thanks for confirming