On Thursday, 26 January 2017 at 23:10:02 UTC, albert-j wrote:
On Thursday, 26 January 2017 at 13:21:38 UTC, Dukc wrote:
import std.stdio, std.algorithm, std.range, std.array;
int[] a = [1, 2, 3, 4, 5, 6, 7, 4];
int[] b = [3, 4, 6];
auto sortedB = sort(b.dup);
auto c = a
. filter!(i => !sortedB.contains(i))
. array
;
assert(c == [1, 2, 5, 7]);
If arrays get large, this should be more efficient since it
performs O(n * n.log) instead of O(n * n).
It does look much faster than my solution. Will it also work
correctly and fast for arrays of custom objects? How should
opCmp() be defined if objects don't have a meaningful ordering?
The order of elements in the original array does not matter.
To me it looks rather slow.
please benchmark!