Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_marks.rb

Instance Method Summary collapse

Instance Method Details

#max_frequencyObject



78
79
80
81
82
# File 'lib/ruby_marks.rb', line 78

def max_frequency
  group_by{ |w| w }
  .map{ |w, v| [w, v.size] }
  .max { |a, b| a[1] <=> b[1] }
end

#to_rangesObject



72
73
74
75
76
# File 'lib/ruby_marks.rb', line 72

def to_ranges
  compact.sort.uniq.inject([]) do |r,x|
    r.empty? || r.last.last.succ != x ? r << [x,x] : r[0..-2] << [r.last.first, x]
  end
end