Letter frequency: Difference between revisions
Content added Content deleted
(→{{header|jq}}: use an object as a hash) |
(→{{header|jq}}: tidy) |
||
Line 1,010:
=={{header|jq}}==
The following program will report the frequency of all characters in the input file, including newlines, returns, etc, provided the file will fit in memory.<lang jq>
▲# The input is an array of int;
▲# the output is an object with the imploded values as keys,
# the values of which are the corresponding frequencies.
def
▲ | reduce .[] as $item ( {}; .[$item] += 1 ) ;
# For neatness we sort the keys:
explode |
| keys | sort[] | [., $counter[.] ]
</lang>
Example:<lang sh>jq -s -R -c -f Letter_frequency.jq somefile.txt</lang>
|