Why uniq do not work with array of strings?
Tobias Pankrath via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Feb 16 10:33:26 PST 2015
On Monday, 16 February 2015 at 18:28:13 UTC, Suliman wrote:
> The question appear here
> http://stackoverflow.com/questions/28546572/how-to-find-duplicates-in-array-of-strings-in-d
>
> I can't understand, why uniq work for array of int but do not
> work with array of strings.
>
> int[] arr = [ 1, 2, 2, 2, 2, 3, 4, 4, 4, 5 ];
> writeln(uniq(arr));
>
> string [] str = ["qwe","asd","zxc", "qwe"];
> auto uniqarr = uniq(str);
>
> foreach(x;uniqarr)
> {
> writeln(x);
> }
>
> Running .\test.exe
> [1, 2, 3, 4, 5]
> qwe
> asd
> zxc
> qwe
>
> ^ "qwe" prints two times.
Works as expected. From the docs:
> Iterates unique -> _consecutive_ <- elements of the given range
Though I concur that the description might be more verbose.
More information about the Digitalmars-d-learn
mailing list