daily pastebin goal
5%
SHARE
TWEET

Untitled

a guest Apr 16th, 2018 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. data = [['a','b'],['c','d','e'],['f','g','h','i']]
  2.  
  3. def combine(a, b)
  4.   if b.is_a?(Array) && !b.empty?
  5.     tmp = []
  6.     c = b.shift
  7.     a.each_with_index do |aa, i|
  8.       c.each do |cc|
  9.         if aa.is_a?(Array)
  10.           tmp.push aa.clone.push(cc) # may be a ruby bug: must use clone
  11.         else
  12.           tmp.push [aa, cc]
  13.         end
  14.       end
  15.     end
  16.    
  17.     if !b.empty?
  18.       return combine(tmp, b)
  19.     else
  20.       return tmp
  21.     end
  22.   end
  23. end
  24.  
  25. p "result:"
  26. result = combine(data.shift, data)
  27. p result
  28. p result.size
RAW Paste Data
Top