Append To Multi-dimensional array where matching matching another array

Viewed 37

I have two arrays:

a = [
  [a, b],
  [c, d],
  [e, f],
  [g, h]
]

b = [
  [a, 4],
  [1, 2],
  [e, 3]
]

when a[i][0], matches b[i][0], I need to add a value to the current index of a. For this example, when a[0][1] matches b[0][1], a[0][1] should look like [a,b,new_value].

If this means creating a new array with all of the values of a, that is fine, but the original values and order of a cannot change.

I have tried numerous variations of for loops and reverse for loops. I am at a loss.

Thanks in advance.

3 Answers
Related