Sha256: 61a947a848205699687b03d88a38e6695ceedb9cf3fb9a90afae75d8b17467d9

Contents?: true

Size: 350 Bytes

Versions: 2

Compression:

Stored size: 350 Bytes

Contents

class Array
  #
  # Returns the middle element of odd-sized arrays. For even arrays,
  # it will return one of the two middle elements. Precisely which is
  # undefined, except that it will consistently return one or the
  # other.
  #
  def sorted_sample num
    return [] if empty?
    (1..num).map{|i| self[(size - 1) * i / (num)]}.uniq
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gorillib-0.4.1pre lib/gorillib/array/sorted_sample.rb
gorillib-0.1.11 lib/gorillib/array/sorted_sample.rb