How to merge multiple arrays in pairs
Posted
by
user3688059
on Stack Overflow
See other posts from Stack Overflow
or by user3688059
Published on 2014-05-29T15:15:42Z
Indexed on
2014/05/29
15:26 UTC
Read the original article
Hit count: 125
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.
© Stack Overflow or respective owner