Sha256: 7cdc9ba2ae121f57d005b4a2328599c8eb067eca0248d423c0201175af40e02b
Contents?: true
Size: 581 Bytes
Versions: 4
Compression:
Stored size: 581 Bytes
Contents
class Array # Returns the middle element of an array, or the element offset # from middle if the parameter is given. Even-sized arrays, # not having an exact middle, return the middle-right element. # # require 'facet/array/middle' # # [1,2,3,4,5].middle #=> 3 # [1,2,3,4,5,6].middle #=> 4 # [1,2,3,4,5,6].middle(-1) #=> 3 # # In other words, If there are an even number of elements the # higher-indexed of the two center elements is indexed as # orgin (0). def middle(offset=0) self.at( (self.length / 2) + offset ) end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
facets-0.6.3 | lib/facet/array/middle.rb |
facets-0.7.0 | lib/facet/array/middle.rb |
facets-0.7.1 | lib/facet/array/middle.rb |
facets-0.7.2 | lib/facet/array/middle.rb |