4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/combinate.rb', line 4
def self.combinate(arrs)
perms = []
(1.upto(arrs.length)).each do |x|
arrs.combination(x).each do |comb|
first = if comb[0].kind_of?(Hash)
[comb[0]]
else
Array(comb[0])
end
if comb.length == 1
first
else
rest = comb[1..-1].map do |e|
if e.kind_of?(Hash)
[e]
else
Array(e)
end
end
first.product(*rest)
end.each do |p|
perms << if p.kind_of?(Hash)
[p]
else
Array(p)
end
end
end
end
perms
end
|