way 1): search a library providing such a function
way 2a): do it manually iterating over all indices (preserve order)
way 2b): do it like 2a) in some way but use ints as keys for hashes
because lookup "seen" might be faster. For that size a simple loop will
suffice.
Have a look at Lambda.hx which applies whenever something is "iterable".
It does not have an unique function yet.
Using "using" you can then do
[1,1].unique();
So consider looking "using" up in online docs. Thus something like this
is probably best you can do (if you don't have very long arrays):
using Lambda;
class MyArrayExtenison {
static public function unique<T>(x:Array<T>, f: T -> T -> Bool):Array<T>{
var r = [];
for (e in x){
if (!r.exists(e, f)) // you can inline exists yourself if you care much about speed. But then you should consider using hash tables or such
r.push(e);
}
return r;
}
}
Marc Weber