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 ^^
Just a small remark: you do not have numbers in your array but
strings. I assume you want to using numeric addition and not string
concatenation. In that case I'd do:
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 ^^
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.
but rejecting the 0 elements will change the length of the array,
and change the resulting average. It depends on whether you want to
generate
the average across all values or the average across all non-zero
values.