The error in these lines:
elsif left.length > 0 result.push(left) left = [] else result.push(right) right = [] end
A simple example should indicate why:
irb(main):067:0> a=[1,2] => [1, 2] irb(main):068:0> b=[3,4] => [3, 4] irb(main):069:0> a.push(b) => [1, 2, [3, 4]]
Instead of push() try concat() .
source share