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!

6
  • What did you try so far? Commented Jun 4, 2013 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! Commented Jun 4, 2013 at 23:05
  • It would be easier to help if you can post your best code so far here as well. Commented Jun 4, 2013 at 23:06
  • I realised I was looking for a Cartesian product of my original array.. And found the result here.. stackoverflow.com/questions/9422386/… god I love this site Commented Jun 7, 2013 at 5:18
  • Why would you want to use "one large jQuery selelector" for this anyway? Do proper separation of concerns and data-binding. Commented Jun 8, 2013 at 15:35

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.