<分区>
我需要检查一个数组,看看它是否只包含另一个数组的某些值。
我可以想办法使用方法 map
和 select
然后使用 includes?
遍历数组,但这会远非高效。
values = ['2','4','5'] # return true if the array only contains these values...
a = ['1', '2', '3']
b = ['1', '2', '4']
c = ['2', '4']
d = ['4', '5']
def compare(checked_array, standard)
# Do something
end
所以,为了我的目的,输出应该是,
- check(a, values) 会返回 false
- check(b, values) 会返回 false
- check(c, values) 会返回 true
- check(d, values) 会返回 true