## digitalmars.D.learn - Why uniq do not work with array of strings?

• Suliman (19/19) Feb 16 2015 The question appear here
• Tobias Pankrath (3/23) Feb 16 2015 Though I concur that the description might be more verbose.
• Tobias Pankrath (2/2) Feb 16 2015 Docs will get a lot better in the next release:
• Suliman (3/4) Feb 16 2015 Could you explain what does it's mean? I do not understand what
• Suliman (2/2) Feb 16 2015 Oh I understood. It's means that it work only of two or more
• Tobias Pankrath (4/6) Feb 16 2015 Yes, uniq returns exactly the same range as its input, except
• Tobias Pankrath (2/4) Feb 16 2015 That's why you'll usually want to sort before using uniq.
"Suliman" <evermind live.ru> writes:
```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.
```
Feb 16 2015
"Tobias Pankrath" <tobias pankrath.net> writes:
```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.
```
Feb 16 2015
"Tobias Pankrath" <tobias pankrath.net> writes:
```Docs will get a lot better in the next release:

http://dlang.org/phobos-prerelease/std_algorithm_iteration.html#uniq
```
Feb 16 2015
"Suliman" <evermind live.ru> writes:
``` Iterates unique -> _consecutive_ <- elements of the given range

Could you explain what does it's mean? I do not understand what
is _consecutive_ mean in this content... and why it's not work
with strings...
```
Feb 16 2015
"Suliman" <evermind live.ru> writes:
```Oh I understood. It's means that it work only of two or more
element's is placed one after one?
```
Feb 16 2015
"Tobias Pankrath" <tobias pankrath.net> writes:
```On Monday, 16 February 2015 at 18:45:17 UTC, Suliman wrote:
Oh I understood. It's means that it work only of two or more
element's is placed one after one?

Yes, uniq returns exactly the same range as its input, except
that elemens that are equal to their immediate predecessor are
dropped.
```
Feb 16 2015
"Tobias Pankrath" <tobias pankrath.net> writes:
```On Monday, 16 February 2015 at 18:45:17 UTC, Suliman wrote:
Oh I understood. It's means that it work only of two or more
element's is placed one after one?

That's why you'll usually want to sort before using uniq.
```
Feb 16 2015