Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Array
- def evens
- get_only :even
- end
- def odds
- get_only :odd
- end
- def get_only(type)
- temp=[]
- type = (type == :even) ? 0 : 1
- self.each_index do |x|
- if((x & 1)==type)
- temp << self[x]
- end
- end
- return temp
- end
- end
Add Comment
Please, Sign In to add comment