【发布时间】:2015-06-28 20:27:17
【问题描述】:
我有一个这样的数字数组...
a= [28, 67, 20, 38, 4, 39, 14, 84, 20, 64, 7, 24, 17, 8, 7, 6, 15, 52, 4, 26]
我需要检查每个数字是否大于 30,如果是,那么我想计算该数字并计算有多少数字大于 30。我有这个,但到目前为止还没有工作
def late_items
total_late = []
if a.map { |i| i > 30}
total_late << i
end
self.late_items = total_late.count
end
【问题讨论】:
-
您只需要项目数还是还需要这些项目在数组中的位置?
-
map总是返回一些东西,所以if永远不会失败。