RosettaCodeData/Task/File-size-distribution/Jq/file-size-distribution.jq
2024-07-13 15:19:22 -07:00

15 lines
522 B
Text

# bag of words
def bow(stream):
reduce stream as $word ({}; .[($word|tostring)] += 1);
# `stream` is expected to be a stream of non-negative numbers or numeric strings.
# The output is a stream of [bucket, count] pairs, sorted by the value of `bucket`.
# No sorting except for the sorting of these bucket boundaries takes place.
def histogram(stream):
bow(stream)
| to_entries
| map( [(.key | tonumber), .value] )
| sort_by(.[0])
| .[];
histogram(.[] | .size | if . == 0 then 0 else 1 + (log10 | trunc) end)