Sort Associative Array by Key

Samir samir at aol.com
Tue Aug 27 16:25:00 UTC 2019


On Sunday, 25 August 2019 at 17:01:23 UTC, a11e99z wrote:
>> auto foo = ["VXE":8, "BZP":5, "JLC":2];
>> foo.byPair.array.sort!"a[0]<b[0]".map!"a[1]".writeln;

On Sunday, 25 August 2019 at 19:03:10 UTC, JN wrote:
> I think normal lambdas are better than these string ones:
>
> foo.byPair.array.sort!((a, b) => a[0] < b[0]).map!(a => 
> a[1]).writeln;

On Sunday, 25 August 2019 at 21:13:05 UTC, Paul Backus wrote:
> You can also use names instead of numeric indices:
>
> foo.byPair.array.sort!((a, b) => a.key < b.key).map!(a => 
> a.value);

a11e99z, JN, Paul:  Thank you all for your replies and help.  As 
I've mentioned on the list before, I really struggle to 
understand how some of the std.algorithm functions such as `map` 
work when combined with things like `array`, `sort` and 
especially `zip` but really appreciate the support I find here on 
the forum.

Samir




More information about the Digitalmars-d-learn mailing list