Given two arrays of equal size, how can I find the number of matching elements disregarding the position?
For example:
[0,0,5]
and[0,5,5]
would return a match of2
since there is one0
and one5
in common;[1,0,0,3]
and[0,0,1,4]
would return a match of3
since there are two matches of0
and one match of1
;[1,2,2,3]
and[1,2,3,4]
would return a match of3
.
I tried a number of ideas, but they all tend to get rather gnarly and convoluted. I'm guessing there is some nice Ruby idiom, or perhaps a regex that would be an elegant answer to this solution.