How to merge multiple arrays in pairs
- by user3688059
I have a problem with "pairing" arrays into one (by index). Here is an example:
INPUT:
inputArray = [ [0, 1, 2, 3, 4], [2, 3, 5, 7, 8], [9, 6, 1] ]
OUTPUT:
outputArray = [
[0,2,9],
[1,3,6],
[2,5,1],
[3,7,chooseRandom()],
[4,8,chooseRandom()]]
Questions:
1) How to avoid out of range problem
2) How to write chooseRandom() to choose N neighbour
I'm using python but feel free to share your thoughts in any language.