David A. Black wrote:
> Hi --
> 
> On Wed, 20 Aug 2008, Lex Williams wrote:
> 
>>        end
>>    end
>> end
>>
>> and then you would have a statistic_hash containing as key a product
>> name , and as value , the number of units sold. I'm not sure about how
>> to calculate the statistics .
> 
> You can use a hash with a default value to make all that hash testing
> easier:
> 
>    statistic_hash = Hash.new(0)
>    array.each do |hash|
>      next unless hash[:did_it_sell]
>      statistic_hash[hash[:title]] += 1
>    end
> 
> 
> David

you could use select on the array , and lose those if's . something like 
this :

array.select { |hash| hash[:did_it_sell] }.each do |hash|
  statistic_hash[hash[:title]] += 1
end
-- 
Posted via http://www.ruby-forum.com/.