How to merge 2 elements within an array

Hi all,

I have one array in this format:
array1=[
[‘a_1_1’,1],
[‘a_1_2’,2],
[‘a_1_3’,2],
[‘a_2_1’,1],
[‘b_1_1’,1]
[‘c_1_1’,1],
]

How do I change it into this format?
array2=[
[‘a_1_1 a_1_2 a_1_3’,1],
[‘a_2_1’,1],
[‘b_1_1’,1]
[‘c_1_1’,1],
]

element 0, 1, and 2 considered the same elements as they all contain
‘a_1’

Thanks,

The specification is a bit unclear. For instance, if the input were

array1=[
[‘a_1_1’,1],
[‘a_2_1’,1],
[‘b_1_1’,1],
[‘a_1_2’,2],
[‘c_1_1’,1],
[‘a_1_3’,2]
]

should the output be the same as in your original case?

No need to be the same orders as long as a_1_1, a_1_2, a_1_3 can be
merged as a string divided by empty space.

And how do you determin the single digit in the output? I.e. why should
the resulting array be

[[‘a_1_1 a_1_2 a_1_3’,1],…]

and not

[[‘a_1_1 a_1_2 a_1_3’,2],…]

?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs