RosettaCodeData/Task/Letter-frequency/Jq/letter-frequency-1.jq
2023-07-01 13:44:08 -04:00

9 lines
320 B
Text

# Input: an array of strings.
# Output: an object with the strings as keys,
# the values of which are the corresponding frequencies.
def counter:
reduce .[] as $item ( {}; .[$item] += 1 ) ;
# For neatness we sort the keys:
explode | map( [.] | implode ) | counter | . as $counter
| keys | sort[] | [., $counter[.] ]