implements matching of elements of different arrays