Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- data = [['a','b'],['c','d','e'],['f','g','h','i']]
- def combine(a, b)
- if b.is_a?(Array) && !b.empty?
- tmp = []
- c = b.shift
- a.each_with_index do |aa, i|
- c.each do |cc|
- if aa.is_a?(Array)
- tmp.push aa.clone.push(cc) # may be a ruby bug: must use clone
- else
- tmp.push [aa, cc]
- end
- end
- end
- if !b.empty?
- return combine(tmp, b)
- else
- return tmp
- end
- end
- end
- p "result:"
- result = combine(data.shift, data)
- p result
- p result.size
Add Comment
Please, Sign In to add comment