module ArrayHelpers
Public Instance Methods
in_two()
click to toggle source
# File lib/nswtopo/helpers/array.rb, line 14 def in_two each_slice(1 + [length - 1, 0].max / 2) end
many?()
click to toggle source
# File lib/nswtopo/helpers/array.rb, line 10 def many? length > 1 end
mean()
click to toggle source
# File lib/nswtopo/helpers/array.rb, line 6 def mean empty? ? nil : inject(&:+) / length end
median()
click to toggle source
# File lib/nswtopo/helpers/array.rb, line 2 def median sort[length / 2] end
nearby_pairs(closed = false, &block)
click to toggle source
# File lib/nswtopo/helpers/array.rb, line 18 def nearby_pairs(closed = false, &block) Enumerator.new do |yielder| each.with_index do |element1, index| (closed ? rotate(index) : drop(index)).drop(1).each do |element2| break unless block.call [element1, element2] yielder << [element1, element2] end end end end