Determining whether one array contains the contents of another array in ruby

Posted by Andrew Grimm on Stack Overflow See other posts from Stack Overflow or by Andrew Grimm
Published on 2010-05-18T07:17:53Z Indexed on 2010/05/18 7:20 UTC
Read the original article Hit count: 176

Filed under:
|

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]
[1, 5, 8, 2, 3, 4, 5].function_name(correct_combination) # => false
[8, 10, 1, 2, 3, 4, 5, 9].function_name(correct_combination) # => true

I tried using include, but that is used to test whether [1,2,3].include?(2) is true or not.

© Stack Overflow or respective owner

Related posts about ruby

Related posts about arrays