I have two arrays with ids
that have linked lengths. By linked lengths I mean that if ArrayA
has length = 4
then ArrayB
will have the length
equal with (ArrayA.length * (ArrayA.length - 1)) / 2
(which means if ArrayA
has length = 4
then ArrayB length = 6
, if ArrayA
has length = 5
then ArrayB length = 10
and so on).
So let’s say these are my arrays: ArrayA = [1, 2, 3, 4]
and ArrayB = [a, b, c, d, e, f]
.
I have to create a new array of arrays
based on the next logic:
In the end the new array should look as it follows, where the second parameter is a value from the first array and the third parameter is a value from the second array:
[
[uuidv4(), 1, a],
[uuidv4(), 2, a],
[uuidv4(), 1, b],
[uuidv4(), 3, b],
[uuidv4(), 1, c],
[uuidv4(), 4, c],
[uuidv4(), 2, d],
[uuidv4(), 3, d],
[uuidv4(), 2, e],
[uuidv4(), 4, e],
[uuidv4(), 3, f],
[uuidv4(), 4, f]
]
In the end, I should return this kind of array no matter the size of the arrays, but the arrays have some kind of linked length.
I can’t do this with a simple mapping because I don’t know how to achieve this kind of logic.
Thank you for your time! If something is unclear, I’ll try to explain better.