Fwd: In search of elegant indices searching

Your result is confusing me:


Not really sure what you’re trying to accomplish, if you want to
determine the indices at which two arrays contain identical values,
you could try:

def comp arr1, arr2
arr1.each_with_index {|val, i|
res.push val==arr2[i]
comp [1,1,3,1,5,6], [1,2,3,1,4,5] # -> [true, false, true, true, false,

if you’d like to determine which values occur in both arrays, try the
intersection operator &:

[1,1,3,1,5,6] & [1,2,3,1,4,5] # -> [1, 3, 5]


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs