Missing array element

Vino.B via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Aug 29 23:16:16 PDT 2017


On Tuesday, 29 August 2017 at 18:39:03 UTC, Ali Çehreli wrote:
> On 08/29/2017 11:20 AM, Vino.B wrote:
>
>> string[] a = ["test1", "test2", "test4"];
>> string[] b = ["test2", "test4"];
>
>> Required output: "test1"
>
> You're looking for setDifference:
>
>   
> https://dlang.org/phobos/std_algorithm_setops.html#.setDifference
>
> Ali

Hi,

  I tried the setDifference but does seem to be working as expected

import std.stdio, std.array, std.algorithm;
string[] a = ["test4", "test3", "test2", "test1"];
string[] b = ["test2", "test4"];
void main ()
{
auto m = setDifference(a,b);
writeln(m);
}

Output : Required output ["test3", "test1"]

["test3", "test2", "test1"]

From,
Vino.B


More information about the Digitalmars-d-learn mailing list