In ruby, how do I test that one array not only has the elements of another array, but contain them in that particular order?
correct_combination = [1, 2, 3, 4, 5
A really quick way to do this is to simply subtract one array from the other and test for an empty array.
correct_combination = [1, 2, 3, 4, 5]
yep = [8, 10, 1, 2, 3, 4, 5, 9]
nope = [1, 8, 2, 3, 4]
if correct_combination - yep == []
puts "yep has all the values"
end
if correct_combination - nope == []
puts "nope has all the values"
end
This approach does not care about position so delete away!
Sorry... I missed the point to the question as well. Didn't realize you were looking for order of precedence. I came across this when looking for a solution to evaluating if one large array contained all the entries of another large array. The .all?/include? approach takes a really long time to complete. Good luck!