given two arrays (of unknown size) like so:
var first = ['A1','A2','A3'];
var second= ['B1','B2'];
I want to get set of all possible pairs from those arrays. In above example proper result should look like this:
var result = [['A1B1','A2B2'], ['A1B1','A3B2'],['A1B2','A2B1'],['A1B2','A3B1'],['A2B1','A3B2'],['A2B2','A3B1']];
I tried to come up with solution on my own, but I am stuck in increasingly bigger numer of nested loops...
EDIT:
Sorry, perhaps I wasn't that clear when forming my question. Maybe it would be easier on an example - let's assume that first array contains names of truck drivers, and second array contains cities. Each driver can only drive to one city, and each city can only be visited by single driver.
In this scenario expected output of the function would be a complete list of possible combinations (driver + city). Unknown lengths of input arrays obviously means that there may be drivers that won't drive anywhere, and there might be cities which won't get visited by any driver.
I hope now my question is more clear now.
EDIT2:
I don't think this is a duplicate of Finding all possible value combinations between two arrays since accepted answer in that question works only (if I understand it correctly) for second array of length 2.