Created
July 19, 2012 19:20
-
-
Save gavinheavyside/3146125 to your computer and use it in GitHub Desktop.
a solution to the alphasights job quiz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# As seen in Ruby Weekly newsletter http://rubyweekly.com/archive/102.html | |
# http://www.alphasights.com/apply/ruby-developer-london | |
by_time = log.reduce(Hash.new{|hash,key| hash[key] = {}}) do |memo, val| | |
memo[val[:time]].merge!(val.reject{|k,v| k == :time}) | |
memo | |
end | |
by_time.map{|k,v| v.merge(time: k)} |
Very nice, I'd completely overlooked group_by! Your solution is much faster too:
user system total real
hgavin 1.810000 0.060000 1.870000 ( 1.862071)
peterc 0.770000 0.020000 0.790000 ( 0.795652)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
OK, I gave it a go. My attempt: