Ruby - Does array A contain all elements of array B
You can try this
a.sort.uniq == b.sort.uniq
or
(a-b).empty?
And if [1,2,2] != [1,2]
in your case you can:
a.group_by{|i| i} == b.group_by{|i| i}
This should work for what you need:
(a & b) == b
You could use Ruby's Set
class:
>> require 'set' #=> true
>> a = [*1..5] #=> [1, 2, 3, 4, 5]
>> b = [*1..3] #=> [1, 2, 3]
>> a.to_set.superset? b.to_set #=> true
For small arrays I usually do the same as what fl00r suggested:
>> (b-a).empty? #=> true