What I want to do is deal with n sets, while the code I provide below works with exactly 4 sets.
def show_combinations
@combos = []
['A', 'no A'].each do |a|
['B', 'no B'].each do |b|
['C', 'no C'].each do |c|
['D', 'no D'].each do |d|
@combos << [a, b, c, d]
end
end
end
end
end
How can I refactor this following code to deal with the following scenario:
Given I have an array of size y containing arrays of size n, I want to return all the combinations.
Background:
A user might have some tasks: for example, “Complete Profile” or “Set Up Email” or whatever. Those tasks can be represented like this:
@task_states = [["Completed Profile, NOT Completed Profile"], ["Set up Email", "NOT set up Email"]]
Then, passing @task_states into the method, the results should be this:
[
["Completed Profile", "Set up Email"],
["Completed Profile", "NOT set up Email"],
["NOT Completed Profile", "Set up Email"],
["NOT Completed Profile", "NOT Set up Email"]
]
So an array of arrays representing all the combinations. Obviously “Completed Profile” can’t also be in the same array as “NOT Completed Profile,” etc.
Thanks!