【发布时间】:2014-03-12 20:36:40
【问题描述】:
我有一个 activerecord 方法可以找到一周的所有事件,
myevents.map { |x| x.start_date.day => [x.title]}
(start_date 是一个日期时间字段,title 是一个字符串)
这给了我一个哈希数组;
[{11=>["40"]}, {11=>["0"]}, {11=>["0"]}, {11=>[""]},
{11=>["0"]}, {11=>["0"]}, {11=>["33"]}, {12=>["9"]},
{11=>["34"]}, {11=>["29"]}, {11=>["8"]}, {11=>["31"]},
{11=>["40"]}, {11=>["34"]}]
我想映射这些值,所以我得到一个看起来像这样的数组;
[ {11=>[ average of values that occur on the 11th]},
{12=>[average of values that occur on the 12th]} ]
但我不太确定如何获得它。
【问题讨论】:
标签: ruby-on-rails ruby arrays hash