I need to check an Array and see if it contains only certain values of another Array.
I can think of ways to do this using the methods map
and select
and then iterating through the array with includes?
but this would be far from efficient.
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
So, for my purpose, output should be,
- check(a, values) would return false
- check(b, values) would return false
- check(c, values) would return true
- check(d, values) would return true