Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

New answers tagged

3

The major thing I see is, the code is imperative. But things will be lot more easier to read and follow, if you practise declarative way of writing code. I would not name the class as DHHScoreChallenge. It should be ScoreChallenge, so that it can be used for any user that we pass in :) I would make the method getData private, in order to externalise the ...


4

The Enumerable.group_by method is perfect for situations like this. The method takes the items in the enumerable, evaluates a block on them to yield a key, and inserts them into a hash under that key. Using this the code is very short: puts(File.open('test.log').entries .group_by { |line| line.split(" ")[4] } .map { |k, v| "#{k},#{v.count}" })


Top 50 recent answers are included