I have seen many questions regarding this, but not one that addresses the issue of duplicate values.
Below are two arrays. I need to verify ary2 is included in ary1 regardless of the extra duplicates. Also needs to work regardless if the arrays are holding numbers or characters.
ary1 = [1, 1, 1, 2, 2, 3, 4, 5, 6]
ary2 = [1, 1, 2, 3, 5]
Should equal [1, 1, 2, 3, 5], my code equals [1, 1, 1, 2, 2, 3, 5]
Tried many options, including keep_if or keep_at, delete_if or delete_at, slice, map, etc.
Current code:
ary1.keep_if { |x| ary2.include?(x) }
ary2is included inary1. That requires atrueorfalseanswer, but you then say the answer should be[1,1,2,3,5]. That makes no sense. Supposeary1 = [1]andary2 = [1,1]. In his case isary2"included" inary1? Please edit your question to clarify what you are asking.