# Re: pulling specific dup. elements out of an array

**URL:** <https://www.ruby-forum.com/t/re-pulling-specific-dup-elements-out-of-an-array/111348>\
**Category:** Ruby\
**Created:** [August 6, 2007, 12:23pm UTC](https://www.ruby-forum.com/t/re-pulling-specific-dup-elements-out-of-an-array/111348 "2007-08-06T12:23:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![stickstone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@stickstone](https://www.ruby-forum.com/u/stickstone)\
**Post date:** [August 6, 2007, 12:23pm UTC](https://www.ruby-forum.com/t/re-pulling-specific-dup-elements-out-of-an-array/111348/1 "2007-08-06T12:23:49Z")

</div>

> 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 do the reject first (use reject! if you want to modify the array  
in-place), and then run your inject on the results of that.

If you prefer to do it all in a single functional-style inject, then I  
guess  
you can do something like this:

array = [‘234234’,‘4593’,‘4098234’,‘0’,‘0’,‘0’]

sum, len = array.inject([0,0]) { |(sum,len),i|  
i != ‘0’ ? [sum+Integer(i),len+1] : [sum,len] }

puts sum / len / 1024
