如何从哈希中输出出现次数最多的电子邮件地址

how to output the highest occurring email address from a hash

我知道这一定存在,我确实遵循了一些似乎是重复问题的答案,所以,我遵循了 ,但遇到了一个小问题。

**我正在尝试从 table 中输出出现次数最多的电子邮件地址并将其显示在视图中。

这是我所做的:

显示动作

module Admin
  module Statistic
    class TrafficsController < BaseController
      def show
        @signup_grid = ::Statistic::TrafficsGrid.new(params[:statistic_traffics_grid])
        @history_assets = @signup_grid.assets
        @highest_occurrence = Hash[@history_assets.group_by {|x| x}.map {|k,v| [k.email,v.count]}]

        @summary = {
            :highest_occurrence_account => @highest_occurrence # this is my output and I have uploaded the hash it outputs instead of the email alone.
        }
        @traffic_filter = true
      end
    end
  end
end

实例变量@highest_occurrence

我的输出

如有必要,请检查以下内容,

这将为您提供哈希[email,objects(with same emails)]

@highest_occurrence = @history_assets.group_by {|x| x.email }

获取最高重复的电子邮件 ID,

@summary = {
  highest_occurrence_account: @highest_occurrence.max_by { |k,v| v.count }[0]
}