def hashJoin(table1, index1, table2, index2)
  
  h = table1.group_by {|s| s[index1]}
  h.default = []
  
  table2.collect {|r|
    h[r[index2]].collect {|s| [s, r]}
  }.flatten(1)
end

table1 = [[27, ],
          [18, ],
          [28, ],
          [18, ],
          [28, ]]
table2 = [[, ],
          [, ],
          [, ],
          [, ],
          [, ]]

hashJoin(table1, 1, table2, 0).each { |row| p row }