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

Content deleted Content added
Thundergnat (talk | contribs)
→‎{{header|Raku}}: Add a Raku example
PureFox (talk | contribs)
→‎{{header|Wren}}: Rewritten to show distinct as well as total numbers of vowels and consonants.
Line 111: Line 111:
System.print(str)
System.print(str)
str = Str.lower(str)
str = Str.lower(str)
var vc = 0
System.write("contains %(str.count { |c| vowels.contains(c) }) vowels and ")
var cc = 0
System.print("%(str.count { |c| consonants.contains(c) }) consonants.")
System.print()
var vmap = {}
var cmap = {}
for (c in str) {
if (vowels.contains(c)) {
vc = vc + 1
vmap[c] = true
} else if (consonants.contains(c)) {
cc = cc + 1
cmap[c] = true
}
}
System.print("contains (total) %(vc) vowels and %(cc) consonants.")
System.print("contains (distinct) %(vmap.count) vowels and %(cmap.count) consonants.\n")
}</lang>
}</lang>


Line 119: Line 131:
<pre>
<pre>
Forever Wren programming language
Forever Wren programming language
contains 11 vowels and 19 consonants.
contains (total) 11 vowels and 19 consonants.
contains (distinct) 5 vowels and 9 consonants.


Now is the time for all good men to come to the aid of their country.
Now is the time for all good men to come to the aid of their country.
contains 22 vowels and 31 consonants.
contains (total) 22 vowels and 31 consonants.
contains (distinct) 5 vowels and 13 consonants.
</pre>
</pre>