我们有这样的数组项:
items = [[[["2012-09-01", 10], ["2011-09-10", 20]]], [[["2010-01-01", 23]]]]
如何将4维项目缩减为2维数组:
items = [["2012-09-01", 10], ["2011-09-10", 20], ["2010-01-01", 23]]
非常感谢。
答案 0 :(得分:5)
尝试Array#flatten。 - http://www.ruby-doc.org/core-1.9.3/Array.html#method-i-flatten
irb(main):001:0> items = [[[["2012-09-01", 10], ["2011-09-10", 20]]], [[["2010-01-01", 23]]]]
=> [[[["2012-09-01", 10], ["2011-09-10", 20]]], [[["2010-01-01", 23]]]]
irb(main):002:0> items.flatten(2)
=> [["2012-09-01", 10], ["2011-09-10", 20], ["2010-01-01", 23]]
答案 1 :(得分:4)