The Easiest way to check if one array is a subset of another

I want to find the easiest way if one array is a subset of another

for example

A b
[1,2,4,5,6,7,9] [1,3,9] =>true

A b
[1,2,4,5,6,7,9] [1,3,8] =>false

Oop, i already found

b.to_set.subset?(a.to_set)

1 Like

A b
[1,2,4,5,6,7,9] [1,3,9] =>true

A b
[1,2,4,5,6,7,9] [1,3,8] =>false

Posted via http://www.ruby-forum.com/.

If I understand correctly what you really want, the first example should
produce false, as array “a” does not have 3. Assuming that you meant
[1,2,3,4,5,6,7,9] I think the following will work for you:

(a & b) == b

Gennady.