Reverse and sort array elements
angel
andrey.gelman at gmail.com
Tue Dec 18 12:32:35 UTC 2018
On Tuesday, 18 December 2018 at 12:07:37 UTC, Andrey wrote:
> Hi,
> Have array:
>> enum array = ["qwerty", "a", "baz"];
> Need to reverse and sort array elements to get this result:
>> [a, ytrewq, zab]
> Did this:
>> enum result = array.map!(value => value.retro()).sort();
> Got:
>> Error: template std.algorithm.sorting.sort cannot deduce
>> function from argument types !()(MapResult!(__lambda1,
>> string[])), candidates are:
> /usr/include/dmd/phobos/std/algorithm/sorting.d(1849,1):
> std.algorithm.sorting.sort(alias less = "a < b", SwapStrategy
> ss = SwapStrategy.unstable, Range)(Range r) if ((ss ==
> SwapStrategy.unstable && (hasSwappableElements!Range ||
> hasAssignableElements!Range) || ss != SwapStrategy.unstable &&
> hasAssignableElements!Range) && isRandomAccessRange!Range &&
> hasSlicing!Range && hasLength!Range)
>
> How to solve the problem?
Did you try this ?
import std.stdio;
import std.algorithm;
import std.range;
import std.conv;
void main()
{
enum input = ["qwerty", "a", "baz"];
enum output = input.map!(value =>
value.retro().to!string()).array.sort();
writeln(input);
writeln(output);
}
More information about the Digitalmars-d-learn
mailing list