Join 2 diff arrays

Hello! How are you and Happy new year! I need Help lol
I doing a exercise of arrays and i need to join 2 arrays like this

def join_values(arr, other_arr)

gets all common values in two arrays (ex.)

join_values([“a”, “b”, “c”], [“c”, “z”, “y”])

=> [“c”]

end

can you help me with the right syntax to do it?,

thank you very much

def join_values(arr, other_arr):
  # we need a place to keep the return values
  result = []
  # iterate one of the arrays
  for x in arr:
    # check for membership in the other array
    if x in other_arr:
      # store the match
      result.append(x)
  # return common values
  return result

>>> join_values(['a', 'b', 'c'], ['c', 'z', 'y'])
['c']
>>> 

thank you very much
you helped me a lot
have a good day!

1 Like