标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1
我创建了数组,我需要找到平均值如下:
total_rating = [] #add numbers to total_rating average = total_rating.inject(:+).to_f / total_rating.size
如何从此平均值计算中删除0值?我不希望在平均计算中计算0行。
答案 0 :(得分:1)
total_rating.reject(&:zero?)