1

Not sure of the best title for this question so any revision suggestions welcome...

say i have 1 javascript array that look like this:

group[g1] = [v1,v2,v3]
group[g2] = [a1,a2,a3]
group[g3] = [b1,b2,b3]
and so on... ad infinitum

and i want to rearrange this to get

newgroup[z] = [v1,a1,b1]
newgroup[y] = [v1,a1,b2]
newgroup[x] = [v1,a1,b3]
newgroup[w] = [v1,a2,b1]
newgroup[v] = [v1,a2,b2]
newgroup[u] = [v1,a2,b3]
newgroup[t] = [v1,a3,b1]
newgroup[s] = [v1,a3,b2]
newgroup[r] = [v1,a3,b3]
newgroup[q] = [v2,a1,b1]
newgroup[p] = [v2,a1,b2]
newgroup[o] = [v2,a1,b3]
newgroup[n] = [v2,a2,b1]
newgroup[m] = [v2,a2,b2]
newgroup[h] = [v2,a2,b3]
newgroup[g] = [v2,a3,b1]
newgroup[f] = [v2,a3,b2]
newgroup[d] = [v2,a3,b3]
newgroup[q] = [v3,a1,b1]
newgroup[p] = [v3,a1,b2]
newgroup[o] = [v3,a1,b3]
newgroup[n] = [v3,a2,b1]
newgroup[m] = [v3,a2,b2]
newgroup[h] = [v3,a2,b3]
newgroup[g] = [v3,a3,b1]
newgroup[f] = [v3,a3,b2]
newgroup[d] = [v3,a3,b3]

i.e.. making a list of all the permutations of the different ways of grouping those items Ideally this would be dynamic so that no matter how many groups there were of elements in each group array.. it would also work. I could then join in newsgroup and link them all together to make one large selector for jquery.

Please help...its beyond me now!

fiscme
  • 422
  • 1
  • 6
  • 20
  • What did you try so far? – mzedeler Jun 04 '13 at 23:03
  • quite a few different methods but nothing with any success. it seems i have to look through the main array and then loop through each array nested in one another. but then i might have a situation of just 2 arrays and missing the 'middle' one! – fiscme Jun 04 '13 at 23:05
  • It would be easier to help if you can post your best code so far here as well. – mzedeler Jun 04 '13 at 23:06
  • I realised I was looking for a Cartesian product of my original array.. And found the result here.. http://stackoverflow.com/questions/9422386/lazy-cartesian-product-of-arrays-arbitrary-nested-loops god I love this site – fiscme Jun 07 '13 at 05:18
  • Why would you want to use "one large jQuery selelector" for this anyway? Do proper separation of concerns and data-binding. – Benjamin Gruenbaum Jun 08 '13 at 15:35
  • I would love to... If I had any idea what that meant. The selector is used in isotope to filter products. If there is a better way I am keen to hear it? – fiscme Jun 08 '13 at 18:45

1 Answers1

0

I realised I was looking for a Cartesian product of my original array.. And found the result here.. Lazy Cartesian product of arrays (arbitrary nested loops)… god I love this site

Community
  • 1
  • 1
fiscme
  • 422
  • 1
  • 6
  • 20