Ruby: Compare 2 arrays for matches, and count the number of match instances

You can do this with array intersection:

@array1 = ['a', 'b', 'c', 'd', 'e']
@array2 = ['d', 'e', 'f', 'g', 'h']
@intersection = @array1 & @array2

@intersection should now be [‘d’, ‘e’]. You can then do the following:

<% if [email protected]? %>
  <%= @intersection.size %> Matches Found.
<% else %>
  No Matches Found.
<% end %>

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)