Letter frequency: Difference between revisions
→{{header|jq}}: use an object as a hash
(jq) |
(→{{header|jq}}: use an object as a hash) |
||
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>
# This function uses an object as a hash table for integers.
#
# the output is an object with the imploded values as keys,
def runs:▼
# the values of which are the corresponding frequencies.
map( [.] | implode )
| reduce .[] as
# For neatness we sort the keys:
explode | count | . as $counts | keys | sort[] | [., $counts[.] ]
</lang>
Example:<lang sh>jq -s -R -c -f Letter_frequency.jq somefile.txt</lang>
{{Out}}
|