On Saturday, 26 August 2017 at 06:11:37 UTC, user1234 wrote:
On Saturday, 26 August 2017 at 06:01:15 UTC, Vino.B wrote:
Hi,

Can someone provide me a example of sorting 2 Dimensional Array containing Filename and Size, and should be sorted by Size.

From,
Vino.B

void main(string[] args)
{
    import std.stdio;
    import std.algorithm.sorting;

    string[2][] nameAndSize = [["b", "2"], ["a", "1"]];
auto s = nameAndSize.sort!((a,b) => a[0] < b[0] && a[1] < b[1]);
    writeln(s);
}

I missed the "by Size" directive. So it's just:

void main(string[] args)
{
    import std.stdio;
    import std.algorithm.sorting;

    string[2][] nameAndSize = [["b", "2"], ["a", "1"]];
    auto s = nameAndSize.sort!((a,b) => a[1] < b[1]);
    writeln(s);
}

Reply via email to