I have four arrays of equal length:
a = [1, 2, 3, 4, 5]
b = ['A', 'B', 'C', 'D', 'E']
c = ['J', 'K', 'L', 'M', 'N']
d = ['v', 'w', 'x', 'y', 'z']
and I want to get an array of all possible combination by taking one element from each of the arrays:
[
[1, 'A', 'J', 'v'],
[2, 'A', 'J', 'v'],
[3, 'A', 'J', 'v'],
...
]
I'm doing this:
master_array = []
for i in first_names do
sub_array = []
for j in last_names do
for k in city do
for l in state do
sub_array.push(i, j, k, l)
end
end
end
master_array.push(sub_array)
end
master_array
Ideally I would like to return an array of hashes, whose keys are the names of the arrays, like so:
[
{a: 1, b: 'A', c: 'J', d: 'v'},
{a: 2, b: 'A', c: 'J', d: 'v'},
{a: 3, b: 'A', c: 'J', d: 'v'},
...
]