-(p1)
public
Array Difference—Returns a new array that is a copy of the original
array, removing any items that also appear in other_ary. (If you
need set-like behavior, see the library class Set.)
[ 1, 1, 2, 2, 3, 3, 4, 5 ] - [ 1, 2, 4 ]
Show source
static VALUE
rb_ary_diff(VALUE ary1, VALUE ary2)
{
VALUE ary3;
volatile VALUE hash;
long i;
hash = ary_make_hash(to_ary(ary2));
ary3 = rb_ary_new();
for (i=0; i<RARRAY_LEN(ary1); i++) {
if (st_lookup(RHASH_TBL(hash), RARRAY_PTR(ary1)[i], 0)) continue;
rb_ary_push(ary3, rb_ary_elt(ary1, i));
}
ary_recycle_hash(hash);
return ary3;
}