Full two-way graph of objects in a nested NSArray

I want to write a method that takes an arbitrary number of NSArray objects and returns a nested array of all possible full combinations of the elements of this array.

As I was told in response to this question, I am looking to create a two-way schedule, or rather, a complete two-way schedule .

So, for example, if I had two arrays:

NSArray *a1 = [NSArray arrayWithObjects:@"Blue", @"Green", @"Yellow", nil];
NSArray *a2 = [NSArray arrayWithObjects:@"Apple", @"Orange", @"Pear", nil];

I need a method that took an array from these arrays:

NSArray *nestedArray = [NSArray arrayWithObjects:a1, a2, nil];

and returned an array of all possible combinations of the same length. So, in this example, I need an array that looks something like this:

 [
      [@"Blue", @"Apple"],
      [@"Blue", @"Orange"],
      [@"Blue", @"Pear"],
      [@"Green", @"Apple"],
      [@"Green", @"Orange"],
      [@"Green", @"Pear"],
      [@"Yellow", @"Apple"],
      [@"Yellow", @"Orange"],
      [@"Yellow", @"Pear"]
]

, , , , . , NSArray. , , . , , , , .

?

+3
2

? , ? , .

+1

, , . , , .

1 , .

0

All Articles