关于转换的问题
如何快速的将:a = [{:one=>1},
{:two=>4},
{:one=>3},
{:three=>3}]
转换为:
a = [{:one=>4},
{:two=>4},
{:three=>3}] h = {}
result = []
a.each do |t|
t.each do |k,v|
if h
h += v
else
h = v
end
end
end
h.each do |k,v|
result << {k=>v}
end没测试, 大概是这样 # data = []
# a.each do |h|
# if data.empty?
# data << h
# else
# eq = false
# data.each_with_index do |h_n,index|
# if h_n.to_a == h.to_a
# eq = true
# h_n] = h_n]+h]
# end
# end
# if !eq
# data<<h
# end
# end
# end
# data 回复 2# coolesting
你写的很简单很不错 回复 4# i_love_ruby
过奖 :em03: 很不错
页:
[1]