Count how many vowels and consonants occur in a string: Difference between revisions

m (→‎{{header|Phix}}: added other distinct)
Line 122:
contains (distinct 5 vowels and 13 consonants.
</pre>
 
=={{header|jq}}==
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
 
This entry focuses solely on the A-Z alphabet.
<lang jq>
def is_lowercase_vowel: IN("a","e","i","o","u");
def is_lowercase_letter: "a" <= . and . <= "z";
def is_lowercase_consonant: is_lowercase_letter and (is_lowercase_vowel|not);
 
def synopsis:
# Output: a stream of the constituent characters
def characters: ascii_downcase | explode[] | [.] | implode;
# For the sake of DRYness:
def s(stream; $vowels; $consonants):
reduce stream as $c ({($vowels): 0, ($consonants):0};
if $c|is_lowercase_vowel then .[$vowels] += 1
elif $c|is_lowercase_consonant then .[$consonants] += 1
else . end);
 
s( characters; "vowels"; "consonants" )
+ s( [characters]|unique[]; "distinct_vowels"; "distinct_consonants" );
 
def task:
def pp: "Synopsis for:", ., synopsis;
 
"Forever HOPL",
"Now is the time for all good men to come to the aid of their country."
| pp, "";
 
task</lang>
{{out}}
<pre>
Synopsis for:
Forever HOPL
{
"vowels": 4,
"consonants": 7,
"distinct_vowels": 2,
"distinct_consonants": 6
}
 
Synopsis for:
Now is the time for all good men to come to the aid of their country.
{
"vowels": 22,
"consonants": 31,
"distinct_vowels": 5,
"distinct_consonants": 13
}
</pre>
 
 
=={{header|Julia}}==
2,502

edits