Last active
December 16, 2015 04:38
-
-
Save michaelfeathers/5378227 to your computer and use it in GitHub Desktop.
Report leading whitespace in a set of files to characterize programmers' indentation conventions.
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
class Array | |
def freq_by &block | |
group_by(&block).map {|k,v| [k, v.count] }.sort_by(&:first) | |
end | |
def freq | |
freq_by {|e| e } | |
end | |
end | |
puts ARGF.lines.map {|l| l.split(/\S/).first } | |
.compact | |
.freq | |
.sort_by {|p,c| -c } | |
.map {|p,c| "%5d %2d: %s" % [c, p.length, p.dump] } | |
.join($/) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment