lib/simple_log_counter/parser.rb
# Parses web log file to dicionary of page counts.
#
# Algorithm centres around a reduction operation, so time complexity =
# O(n)
Parses web log file to dicionary of page counts.
Algorithm centres around a reduction operation, so time complexity
O(n)
Parses web log file to dicionary of page counts . Algorithm centres around a reduction operation so time complexity O ( n )
def unique_visitor_counter(log)
        counter = Hash.new { |h, k| h[k] = Set.new }
        log.each_line
           .each_with_object(counter) { |line, hsh| hsh[page_from_line(line)].add(visitor_from_line(line)) }
           .map { |page, visitors| [page, visitors.size] }
      end
def unique_visitor_counter ( log ) counter = Hash . new { | h , k | h [ k ] = Set . new } log . each_line . each_with_object ( counter ) { | line , hsh | hsh [ page_from_line ( line ) ] . add ( visitor_from_line ( line ) ) } . map { | page , visitors | [ page , visitors . size ] } end
Parses web log file to dicionary of page counts.
Parses web log file to dicionary of page counts .
log