From: Stefan Rusterholz Date: 2007-08-07T00:08:50+09:00 Subject: Re: pulling specific dup. elements out of an array Jon Hawkins wrote: > Chris wrote: >> why didn't reject work? >> >>>> array = ['234234','04593','4098234','0','0','0'] >> => ["234234", "04593", "4098234", "0", "0", "0"] >>>> array.reject {|e| e == '0' } >> => ["234234", "04593", "4098234"] > > well lemme further explain what im attempting to do and why i couldnt > get reject to work right, i need to delete all the 0's in the array then > add up those non-zero numbers. > with: > > array.inject(0) {|num, i| num + i}/array.length/1024 #1024 = > kilobytes convert > > so if theres a way to shove reject into that then lemme know ^^ > > Thanks > -Jon Why do you want to remove the 0 elements for that? They won't influence the result: avg_kb = array.inject(0.0) { |sum,num| sum + num.to_f }/array.length/1024 If you don't want the average without zero-size files write array.delete('0') in the line before, as Daniel Lucraft already pointed out. Regards Stefan -- Posted via http://www.ruby-forum.com/.