I'm hoping there's a simple way to do this or perhaps I can get some ideas on which direction to go. I've built a 2D NSArray of NSArrays. The primary array will be of variable length (usually less than 10) and the secondary arrays will also be variable, usually less than 5, but each one may be different, the first may be 2, the second may be 3, etc. I need to traverse them and build all the unique combinations of the elements.

For instance, I have
NSArray *numbers containing 1,2 and 3
NSArray *letters containing A and B
NSArray *colors containing Red, White, Blue.

I need to build an array of objects we'll call combos:
combo1: 1, A, Red
combo2: 1, A, White
combo3: 1, A, Blue
combo4: 1, B, Red
combo5: 1, B, White
.
.
.
combo18: 3, B, Blue

This is relatively easy if I know how many arrays I'm working with (3 in this case) to simply nest the for loops but if I don't know how many arrays the primary array has, I can't think of a way to nest the loops if I don't know how deeply to nest them. Any suggestions on the best way to approach something like this?


Ashley Perrien
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to