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 |
→{{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 |
|||
⚫ | |||
var cc = 0 |
|||
⚫ | |||
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 |
|||
} |
|||
} |
|||
⚫ | |||
⚫ | |||
}</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> |