【发布时间】:2009-07-23 01:19:03
【问题描述】:
假设@houses 数组设置如下:
house1.price = 10
house2.price = 20
house3.price = 30
@houses << house1
@houses << house2
@houses << house3
这是我们计算的起点,我们要找到房子的平均价格:
total = 0
average = 0
for h in @houses
total += h.price
end
average = total/@houses.size
这似乎是为了得到一个平均数。
有没有更好的办法?
【问题讨论】: